C - Lucky Conversion

CodeForces - 146C

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:

  • replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);
  • swap any pair of digits in string a.

Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.

Input

The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.

Output

Print on the single line the single number — the minimum number of operations needed to convert string a into string b.

Examples

Input
47
74
Output
1
Input
774
744
Output
1
Input
777
444
Output
3

Note

In the first sample it is enough simply to swap the first and the second digit.

In the second sample we should replace the second digit with its opposite.

In the third number we should replace all three digits with their opposites.

题意:给出两个字符串a,b,对字符串a进行两种操作:1.将4替换为7或将7替换为4 (2. 交换字符串中的任意两个数,求出最少操作数使得字符串a与字符串b相等

题解:记录下a与b中对应位置不同的数的个数,即与b串中对应位置不同且a串为4的个数(用ct4表示)或a串中7的个数(ct7表示),如果不考虑交换操作,那么操作次数为ct4+ct7;

如果ct4与ct7均不为0,那么就可以进行交换操作,所以可以交换的次数应为min(ct4,ct7),那么最终的操作次数为ct4+ct7-min(ct4+ct7)

#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,b;
int ct4=0,ct7=0;
cin>>a>>b;
int n;
n=a.size();
for(int i=0;i<n;i++)
{
if(a[i]==b[i])continue;
if(a[i]=='4')ct4++;
else ct7++;
}
cout<<(ct4+ct7-min(ct4,ct7))<<endl;
}

B - Lucky Mask

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya calls a mask of a positive integer n the number that is obtained after successive writing of all lucky digits of number n from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number.

Petya has two numbers — an arbitrary integer a and a lucky number b. Help him find the minimum number c (c > a) such that the mask of number c equals b.

Input

The only line contains two integers a and b (1 ≤ a, b ≤ 105). It is guaranteed that number b is lucky.

Output

In the only line print a single number — the number c that is sought by Petya.

Examples

Input
1 7
Output
7
Input
100 47
Output
147
题解:输入两个整数a,b,用数组x[]将a的各位数存储起来,因为要求的c比a大,所以从i=a+1开始遍历,将i的各位数存入数组y[]
中,遍历该数组,看是否存在数与a相同且无多余的幸运数
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,x[100],y[100];
while(cin>>a>>b)
{
int n,m,k=0,p=0;
m=b;
while(m>0)
{
x[k++]=m%10;
m/=10;
}
for(int i=a+1; ;i++)
{
n=i;
p=0;
while(n!=0)
{
y[p++]=n%10;
n/=10;
}
int w,j,s=0;
for(w=0,j=0;w<p;w++)
{
if(y[w]==4||y[w]==7)
{
if(y[w]==x[j])
{
j++;
}
else//当数值为147777 47 ,i=147778,不符合要跳出,重新遍历
{
s=1;
break;
}
}
}
if(s==1)
{
continue;
}
if(j==k)
{
cout<<i<<endl;
break;
}
}
} }

2020.12.14--Codeforces Round #104 (Div.2)补题的更多相关文章

  1. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. Codeforces Round #786 (Div. 3) 补题记录

    小结: A,B,F 切,C 没写 1ll 对照样例才发现,E,G 对照样例过,D 对照样例+看了其他人代码(主要急于看后面的题,能调出来的但偷懒了. CF1674A Number Transforma ...

  3. Codeforces Round #429 (Div. 2) 补题

    A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...

  4. Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

    A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...

  5. Codeforces Round #590 (Div. 3)补题

    要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ∅ √ 解 E 待定 F 传送门 第一 ...

  6. Codeforces Round #574 (Div. 2)补题

    A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 >  Σki / 2 ? (n + 1)/2 - Σki / ...

  7. Codeforces Round #585 (Div. 2) [补题]

    前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...

  8. Codeforces Round #615 (Div. 3) 补题记录

    第一次搞CF,结果惨不忍睹...还是太菜了 A:要用到全部的钱,所以总数必须是3的倍数,而且初始状态下任意一人的钱数不能超过总数除以3,否则没法分了 (也就这个签到算是在我能力范围之内了....) # ...

  9. Codeforces Round #617 (Div. 3) 补题记录

    1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...

随机推荐

  1. idea控制台中文乱码解决办法

    也可以通过idea右下角的设置,但是properties文件是不能设置的,这个只能在file->setting->file encodings 设置

  2. PXC 5.7.14 安装部署

    http://www.dbhelp.net/2017/01/06/pxc-5-7-14-%E5%AE%89%E8%A3%85%E9%83%A8%E7%BD%B2-pxc-install.html PX ...

  3. Centos8.3安装broadcom(博通)BCM43142无线网卡驱动,Centos8没有wifi选项(No wifi adapter found centos)解决办法

    参考:杆菌大祭司> https://www.jianshu.com/p/3cb41b7b8fec 第一步:查看网卡型号,确认无线网卡型号为BCMXXX lspci | grep Network ...

  4. Linux--MySQL 日志管理、备份与恢复

    MySQL 日志管理.备份与恢复一.MySQL 日志管理二.数据库备份的重要性与分类  1.数据备份的重要性  2.从物理与逻辑的角度,备份分为  3.从数据库的备份策略角度,备份可分为三.常见的备份 ...

  5. J2EE分布式微服务云开发架构 Spring Cloud+Mybatis+ElementUI 前后端分离J2EE分布式微服务云开发架构 Spring Cloud+Mybatis+ElementUI 前后端分离

    ​ 鸿鹄云架构[系统管理平台]是一个大型企业.分布式.微服务.云架构的JavaEE体系快速研发平台,基于模块化.微服务化.原子化.热部署的设计思想,使用成熟领先的无商业限制的主流开源技术(Spring ...

  6. 从输入 URL 到展现页面的全过程

    总体分为以下几个过程 DNS解析 TCP连接 发送HTTP请求 服务器处理请求并返回HTTP报文 浏览器解析渲染页面 连接结束 DNS解析 域名到ip地址转换 TCP连接 HTTP连接是基于TCP连接 ...

  7. PHP设计模式之备忘录模式

    备忘录,这个名字其实就已经很形象的解释了它的作用.典型的例子就是我们原来玩硬盘游戏时的存档功能.当你对即将面对的大BOSS有所顾虑时,一般都会先保存一次进度存档.如果挑战失败了,直接读取存档就可以恢复 ...

  8. 【TP3.2.3】根据字段统计条数

    // 省份查询 $province = M('hospital') -> field('area as label,count(*) as value') -> group('area') ...

  9. Docker系列(11)- 部署Nginx

    step-1 搜索镜像 使用search命令,建议去dockerhub上搜索,可以看到帮助文档 [root@localhost ~]# docker search nginx NAME DESCRIP ...

  10. python学习笔记(十五)-unittest单元测试的一个框架

    unittest 单元测试的一个框架什么框架 一堆工具的集合. TestCase TestSuite 测试套件,多个用例在一起 TestLoader是用来加载TestCase到TestSuite中的 ...