1. 程式人生 > >洛谷 P2708 硬幣翻轉

洛谷 P2708 硬幣翻轉

targe style www cin code lan std return ble

P2708 硬幣翻轉

模擬

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define maxn 10000000
 4 
 5 int a[maxn],ans;
 6 char s[maxn];
 7 int main()
 8 {
 9     cin>>s;
10     for(int i=0;i<strlen(s);i++) a[i+1]=s[i]-0;
11     int n=strlen(s);
12     while(n)
13     {
14         if
(a[n]==0) 15 { 16 ans++; 17 for(int i=n;i>=1;i--) a[i]=a[i]^1; 18 } 19 n--; 20 } 21 22 printf("%d",ans); 23 return 0; 24 }

洛谷 P2708 硬幣翻轉