革命尚未成功

————同志仍需努力————

shinnyblue

导航

翻硬币 | 递推

 

P8597 [蓝桥杯 2013 省 B] 翻硬币 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)

 

 

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 #define ios_base \
 5     ios::sync_with_stdio(false); \
 6     cin.tie(nullptr),cout.tie(nullptr)
 7 string str,s0;
 8 inline void update(char& ch)
 9 {
10     if (ch=='*')
11     {
12         ch='o';
13     }else{
14         ch='*';
15     }
16     
17 }
18 int res=0;
19 int main()
20 {
21     ios_base;
22     cin>>str>>s0;//s0是目标字符串,str是需要改动的字符串
23     for(int i=0;i<s0.size()-1;i++)
24     {
25         if (str[i]!=s0[i])
26         {
27             update(str[i]);
28             update(str[i+1]);
29             res++;
30         }
31         
32     }
33     cout<<res;
34     return 0;
35 }

 

posted on 2023-03-29 16:36  ShinnyBlue  阅读(12)  评论(0编辑  收藏  举报

Live2D