fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void smallestNumber(string pattern) {
  5. stack<int> stack;
  6. string num;
  7. for(int i=0; i<=pattern.length(); i++) {
  8. stack.push(i+1);
  9. if(pattern[i] == 'I' || i == pattern.length()) {
  10. while(!stack.empty()) {
  11. num += stack.top() + '0';
  12. stack.pop();
  13. }
  14. }
  15. // cout << num << endl;
  16. }
  17. cout << num << endl;
  18. }
  19.  
  20. int main() {
  21. string input;
  22. for(int i=0; i<4; i++) {
  23. cin >> input;
  24. smallestNumber(input);
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5292KB
stdin
IIIDIDDD
IID
DDD
IIIDIDD
stdout
123549876
1243
4321
12354876