1 solutions
-
0
#include <bits/stdc++.h> #define i64 long long using namespace std; const int N = 500005; char s[N]; int main(){ int n; cin >> n; cin >> (s+1); int cntj = 0, cntoi = 0; for (int i = 1;i <= n;i++) { if (s[i] == 'J') { cntj++; } else if (s[i] == 'O' && s[i+1] == 'I'){ cntoi++; i++; } else { for (int j = 1;j <= cntoi;j++) cout << "OI"; for (int j = 1;j <= cntj;j++) cout << "J"; cntoi = cntj = 0; cout << s[i]; } } for (int j = 1;j <= cntoi;j++) cout << "OI"; for (int j = 1;j <= cntj;j++) cout << "J"; cntoi = cntj = 0; }
- 1
Information
- ID
- 40
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 51
- Accepted
- 12
- Uploaded By