Please read the new rule regarding the restriction on the use of AI tools. ×

garibcoder's blog

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:(

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

| Write comment?
»
4 years ago, # |
  Vote: I like it +13 Vote: I do not like it

Format the code you pasted, otherwise you will not get others to look at it. Also explain your approach briefly and mention on which input you got segmentation fault.