程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces 145A-Lucky Conversion

Codeforces 145A-Lucky Conversion

編輯:C++入門知識

Codeforces 145A-Lucky Conversion


A. Lucky Conversion time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

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 ainto string b.

    Sample test(s) input
    47
    74
    
    output
    1
    
    input
    774
    744
    
    output
    1
    
    input
    777
    444
    
    output
    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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved