ninja12345's blog

By ninja12345, history, 4 weeks ago, In English

https://codeforces.com/problemset/problem/266/A int solve() { int n, c = 0; char cc, prev = 0; cin>>n; while(n--){ scanf("%c",&cc); if (cc == prev) c++; prev = cc; }

return c;

}

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

You writed prev=0 right? Now try to write prev='0'

I think now it'll work correct.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Mate you have assigned "char prev=0" which is incorrrect. Try it with char prev = '0' . It will surely work for you. I am giving my other implementation way as well!

include<bits/stdc++.h>

using namespace std; int main(){ int n,count=0; cin>>n; string a; cin>>a; int len=a.length(); for(int i=0;i<len-1;i++){ if(a[i]==a[i+1]){ count++; } } cout<<count; return 0; }