fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int angkaCantik(string s, string osn) {
  6. int a = 0;
  7. for(int i = 0; i<s.length(); i++) {
  8. if(s[i] == osn[a % 3]) {
  9. a++;
  10. }
  11. }
  12. if(a < 3) a = -1;
  13. return a;
  14. }
  15.  
  16. int main() {
  17. string s;
  18. cin >> s;
  19.  
  20. int counter = -1;
  21. vector<string> arr = {"OSN", "SNO", "NSO", "NOS", "SON", "ONS"};
  22. for(int i = 0; i<arr.size(); i++) {
  23. int baru = angkaCantik(s, arr[i]);
  24. if(baru > counter)
  25. counter = baru;
  26. }
  27.  
  28. cout << counter << endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5288KB
stdin
OLIMPIADESAINSNASIONALTINGKATPROVINSI
stdout
6