[蓝桥杯●历届真题]:翻硬币

    科技2025-12-22  25

    题目描述:

    考察点: 模拟,贪心

    Code:

    #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> using namespace std; string str1,str2; int cnt = 0; int main(void) { cin >> str1 >> str2; for(int i = 0; i < str1.length(); i ++) { if(str1[i] != str2[i]) { if(str1[i] == '*') { str1[i] = 'o'; if(str1[i + 1] == '*') { str1[i + 1] = 'o'; } else { str1[i + 1] = '*'; } } else { str1[i] = '*'; if(str1[i + 1] == '*') { str1[i + 1] = 'o'; } else { str1[i + 1] = '*'; } } cnt ++; } } cout << cnt << endl; return 0; }

    Processed: 0.018, SQL: 9