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:
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.
InputThe 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.
OutputPrint on the single line the single number — the minimum number of operations needed to convert string ainto string b.
Sample test(s) input47 74output
1input
774 744output
1input
777 444output
3
不得不承認CF上的題確實質量很好,這題還是A題就卡了好一陣,思路很詭異。。
題意: 給出一串字符串,只包含數字4和7 然後再給出另一個字符串,同樣是只包含4和7,長度相同,現在給定兩種操作,①:改變a串某位上的數字;②:交換a串任意兩位上的數字,求最小操作數 使得a==b
因為是要最小操作數,所以要盡可能的執行交換操作,所以 掃一遍a串,看它和b串的對應位置上的數字是不是相同,若不同,記下4和7不同的個數,其中最大數就是答案。
#include#include #include #include #include #include using namespace std; #define LL long long const int maxn=100050; char s[maxn],t[maxn]; int main() { while(~scanf("%s%s",s,t)) { int len=strlen(s),cnt1=0,cnt2=0; for(int i=0;i