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
Problem Description

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.

 

Input

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.

 

Output

Print on the single line the single number the minimum number of operations needed to convert stringa into stringb.

 

Sample Input
4774774744
 

Sample Output
11
 

Source
Codeforces

题意:用交换任意两个字符或替换与之对应的字符使两个字符串相等;

                         本题只需找出对应不相等的字符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);    }}



原创粉丝点击