Codeforces 1265A. Beautiful String Solution

Solve in C++:
  1. ///**********ALLAH IS ALMIGHTY************///
  2. ///AH Tonmoy
  3. ///Department of CSE
  4. ///Islamic University,Bangladesh
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7. int main()
  8. {
  9. int n,t,i,j,l,f=0,c=0;
  10. string s,s1;
  11. while(cin>>t)
  12. {
  13. while(t--)
  14. {
  15. f=0,c=0;
  16. cin>>s;
  17. l=s.size();
  18. for(i=0; i<l; i++)
  19. {
  20. if((s[i]==s[i+1])&&(s[i]=='a'||s[i]=='b'||s[i]=='c'))
  21. {
  22. cout<<"-1"<<endl;
  23. c=1;
  24. break;
  25. }
  26. }
  27. if(c==0)
  28. {
  29. for(i=0; i<l; i++)
  30. {
  31. if(s[i]=='?')
  32. for(j='a'; j<='c'; j++)
  33. {
  34. if(j!=s[i-1]&&j!=s[i+1])
  35. s[i]=j;
  36. }
  37. }
  38. for(i=0; i<l; i++)
  39. {
  40. cout<<s[i];
  41.  
  42. }
  43. cout<<endl;
  44.  
  45. }
  46. }
  47.  
  48. }
  49. }
  50.  

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.