Why is my code facing a TLE?

Revision en2, by sai_aasish, 2024-04-15 19:05:48

Hey CF!, I came up with a solution to the below mentioned question and my code is getting a tle. What could be the problem? click here to view the problem

My code:

include <bits/stdc++.h>

using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; string s; cin>>s; string a= "";//taking an empty string to store the output int i= n-1; while(i>= 0)//traversing the string from the rear { if(s[i] != 'a' && s[i] != 'e')//if its not a vowel, concatinating the last three elements to the "a" string { a= a+s[i]; a= a+s[i-1]; a= a+s[i-2]; a= a+'.'; i= i-3; } else//else, concatinating the last two elements to the "a" string { a= a+s[i]; a= a+s[i-1]; a= a+'.'; i= i-2; } } a.pop_back();//popping out the last "." reverse(a.begin(), a.end());//reversing the output since I traversed from the rear cout<<a<<endl; } return 0; }

please let me know what is wrong in this code, thanking you.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English sai_aasish 2024-04-15 19:27:22 98
en4 English sai_aasish 2024-04-15 19:15:22 196
en3 English sai_aasish 2024-04-15 19:07:07 442
en2 English sai_aasish 2024-04-15 19:05:48 5 Tiny change: '915/D)\n\n#### My code:\n' -> '915/D)\n\nMy code:\n'
en1 English sai_aasish 2024-04-15 19:05:16 1365 Initial revision (published)