Advertisement
Rofyda_Elghadban1

Untitled

Mar 12th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define pi 3.141592654
  5. #define NUM 1e18
  6. #define Mod 1'000'000'007
  7. #define fixed(n) fixed<<setprecision(n)
  8. #define cin(v) for(auto &i:v) cin >> i ;
  9. #define cout(v) for(auto &i:v) cout << i <<" ";
  10. #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11. #define small(x) (x>=97&&x<=122)
  12. #define capital(x) (x>=65&&x<=90)
  13. #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14. #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15. #define sz(x) (int)(x.size())
  16. #define all(v) ((v).begin()), ((v).end())
  17. #define allr(v) ((v).rbegin()), ((v).rend())
  18. #define updmax(a,b) a=max(a,b)
  19. #define updmin(a,b) a=min(a,b)
  20. #define ceil(a,b) ((a/b)+(a%b?1:0))
  21. /* asc -> 1 2 3 ,des -> 3 2 1 */
  22.  
  23. /***********************************************************************************/
  24. using namespace std;
  25. void Rofyda_Elghadban(){
  26. #ifndef ONLINE_JUDGE
  27. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28. #endif
  29. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  30. }
  31.  
  32. void solve(){
  33. int n,counter=0;
  34. cin>>n;
  35. string s;
  36. cin>>s;
  37. vector<string>v;
  38. string temp;
  39. for(int i=0;i<n;i++){
  40. if(s[i]=='m'&&temp.back()!='p'&&temp.back()!='a'){
  41. temp.push_back(s[i]);
  42. }else if(s[i]=='a'){
  43. if((temp.back()=='m'||temp.back()=='a')){
  44. temp.push_back(s[i]);
  45. }
  46. }else if(s[i]=='p'){
  47. if((temp.back()=='a'||temp.back()=='p')){
  48. temp.push_back(s[i]);
  49. }
  50. }else{
  51. counter++;
  52. v.push_back(temp);
  53. v.push_back(" ");
  54. temp.clear();
  55. }
  56. }
  57. if(counter==0){
  58. v.push_back(temp);
  59. }
  60. cout(v);
  61. cout<<"\n";
  62. }
  63.  
  64. int main(){
  65. Rofyda_Elghadban();
  66. int t=1;
  67. cin>>t;
  68. while(t--){
  69. solve();
  70. }
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement