翻硬币-贪心
思路:
其实这道题就是比较与给出的字符串的不同,翻转的时候,只需要考虑当前的一步就行;
代码:
#include <iostream>
using namespace std;
string str1,str2;
auto turnover(char s){
if(s=='*') return 'o';
else return '*';
}
int main()
{
cin>>str1>>str2;
int i,cnt=0,len=str1.length()-2;
for(i=0;i<=len;i++){
if(str1[i]!=str2[i]) str1[i]=turnover(str1[i]),str1[i+1]=turnover(str1[i+1]),cnt++;
else ;
}
cout<<cnt;
// 请在此输入您的代码
return 0;
}