garibcoder's blog

By garibcoder, history, 4 years ago, In English

How to solve this problem using minimum number of operations?

Full text and comments »

  • Vote: I like it
  • +7
  • Vote: I do not like it

By garibcoder, history, 4 years ago, In English

Can you guys help me out with the following code.On compilation it is showing segmentation fault.

int n; cin>>n; string s; cin>>s; int j=0; char c; while(s[j]&&s[j]==s[n-1]) { s.push_back(s[n-1]); j++; } int ans=0;

for(int i=j;i<s.length();i++) { int ctr=0; c=s[i]; while(s[i]&&s[i]==c) { ctr++; i++; } if(ctr>=3) ans+=ctr/3; }

cout<<ans; cout<<s; cout<<"\n";

P.S.:-This is the solution of Problem 1392D Omkar and Bed Wars recently asked in Global Codeforces round 10.Please help me:(

Full text and comments »

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