fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int c = 0, d = 0, n;
  7. cin >> n;
  8. while (n--) {
  9. string s;
  10. cin >> s;
  11. if (s == "for") {
  12. ++d;
  13. c = max(c, d);
  14. } else if (s == "end") {
  15. --d;
  16. }
  17. }
  18. if (c == 0) {
  19. cout << "O(1)" << endl;
  20. } else if (c == 1) {
  21. cout << "O(n)" << endl;
  22. } else {
  23. cout << "O(n^" << c << ")" << endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 15240KB
stdin
18
instruction
for
for
instruction
end
for
instruction
instruction
instruction
for
instruction
instruction
end
instruction
end
end
instruction
instruction
stdout
O(n^3)