Codeforces 145A Lucky Conversion(思维)
来源:互联网 发布:ibm linux 编辑:程序博客网 时间:2024/06/04 23:34
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 7by 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.
The first and the second line contains strings a and b, correspondingly. Strings aand b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Print on the single line the single number — the minimum number of operations needed to convert string a into string b.
4774
1
774744
1
777444
3
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.
题解:
直接扫两个串记录不同时候的4和7的个数,取最大值
代码:
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#include<stdio.h>using namespace std;#define ll long longint main(){ char s1[100005],s2[100005]; int i,j,d1=0,d2=0; scanf("%s%s",s1,s2); for(i=0;s1[i];i++) { if(s1[i]!=s2[i]) { if(s1[i]=='7') d1++; else d2++; } } printf("%d\n",max(d1,d2)); return 0;}
- Codeforces 145A Lucky Conversion(思维)
- Codeforces 145A-Lucky Conversion(规律)
- CodeForces 808A Lucky Year(思维)
- Codeforces 303A Lucky Permutation Triple【思维】
- Codeforces---Lucky Conversion
- A. Lucky Conversion
- Codeforces 303A Lucky Permutation Triple 【构造 思维】
- codeforces 122A(Lucky Division) Java
- 【CodeForces】A. Lucky Division
- CodeForces 808A——Lucky Year——思维,模拟
- CodeForces 122A Lucky Division
- CodeForces 122A Lucky Division
- codeforces 808A Lucky Year
- 【Codeforces 808 A. Lucky Year】
- codeforces 122A Lucky Division
- codeforces 856A (思维)
- codeforces 110A(Nearly Lucky Number) Java
- CodeForces 303 A.Lucky Permutation Triple(构造)
- Texture ‘XXX' is not readable, the memory can not be accessed form scripts, You can make the texture
- HashMap的底层粗介
- 浅谈MySQL Online DDL(下)
- ajax技术,也是有局限的,不能跨域,即A工程的html页面发起一个ajax请求即http url请求调B工程的action(A和B不在一个域中的),怎么办?解决办法
- 使用typeperf监控系统资源
- Codeforces 145A Lucky Conversion(思维)
- 深度学习之入门
- cdn
- Nginx的使用
- HashMap和HashTable到底哪不同?
- 八大排序算法
- 加减计算器(数电)
- JAVA | 52
- ubuntu安装proxychains及自动补全