Codeforces---Lucky Conversion
来源:互联网 发布:mac智能文件夹怎么用 编辑:程序博客网 时间:2024/06/06 20:18
Lucky Conversion
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other)
Total Submission(s) : 42 Accepted Submission(s) : 11
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits4 and7. For example, numbers47,744,4 are lucky and5, 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 performoperations of two types:
- replace any one digit from string a by its opposite (i.e., replace4 by7 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 stringa equal to stringb. Help him with the task.
The first and the second line contains strings a andb, correspondingly. Stringsa and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed105.
Print on the single line the single number the minimum number of operations needed to convert stringa into stringb.
4774774744
11
题意:用交换任意两个字符或替换与之对应的字符使两个字符串相等;
本题只需找出对应不相等的字符4和7的个数的最大值即为所求;
#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int main(){ char s1[100005],s2[100005]; while(cin>>s1>>s2) { int l=strlen(s1); int k=0,sum=0,i; for(i=0;i<l;i++) { if(s1[i]!=s2[i]&&s1[i]=='4') k++; if(s1[i]!=s2[i]&&s1[i]=='7') sum++; } int ans=max(k,sum); printf("%d\n",ans); }}
- Codeforces---Lucky Conversion
- Codeforces 145A-Lucky Conversion(规律)
- Codeforces 145A Lucky Conversion(思维)
- A. Lucky Conversion
- codeforces Lucky Sum
- 【CodeForces】A. Lucky Division
- Lucky Permutation Triple CodeForces
- Lucky Numbers (easy) CodeForces
- codeforces 145E - Lucky Queries
- CodeForces 122A Lucky Division
- CodeForces 122A Lucky Division
- Codeforces 109 C. Lucky Tree
- CodeForces-630C. Lucky Numbers
- Codeforces 630C Lucky Numbers
- CodeForces-630C. Lucky Numbers
- CodeForces 630C:Lucky Numbers
- CodeForces - 630C Lucky Numbers
- 【CodeForces】[630C]Lucky Numbers
- .net获取串口列表
- leetcode Jump Game
- Android服务启动之StartService源码分析
- SQL Server 2000安装遇到的问题
- VirtualBox Ubuntu 12.04 Access Windows 7 File System
- Codeforces---Lucky Conversion
- 安卓应用程序无反应分析
- sql常用语句
- 集训两次周赛总结
- 1+Null 居然等于 Null
- golang 中的 "继承" -----组合
- 停停走走享受生活-今日工作规划-2013.07.20
- 提升tomcat服务器性能的七条经验
- 学习笔记#1