题解:简单贪心, 比赛之前写写水题
#include <iostream> #include <cstring> #include <string> using namespace std; const int maxn = 1000 + 20; void solve() { int init[maxn], over[maxn]; string in, ov; int ans = 0; cin >> in; cin >> ov; for (unsigned i = 0; i < in.length(); i++) { if (in[i] == ‘*‘) { init[i] = 1; } else { init[i] = 0; } if (ov[i] == ‘*‘) { over[i] = 1; } else { over[i] = 0; } } for (unsigned i = 0; i < in.size() - 1; i++) { if (init[i] != over[i]) { init[i] = over[i]; init[i+1] = !init[i+1]; ans++; } } cout << ans << endl; } int main() { solve(); return 0; }
原文地址:https://www.cnblogs.com/douzujun/p/8543860.html
时间: 2024-10-03 22:30:28