fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. using namespace std;
  5. int solve(const string &s) {
  6. map<char, int> m;
  7. for (auto c : s) ++m[c];
  8. if (m.size() == 2) {
  9. if (m['g'] == 0) return m['c'];
  10. if (m['c'] == 0) return m['p'];
  11. if (m['p'] == 0) return m['g'];
  12. }
  13. return 0;
  14. }
  15.  
  16. int main() {
  17. for (string s; cin >> s; ) cout << s << " -> " << solve(s) << endl;
  18. }
  19.  
Success #stdin #stdout 0s 4544KB
stdin
gccgc
ggggggg
cppcppppccpppppc
cppcppppccpgpppc
stdout
gccgc -> 2
ggggggg -> 0
cppcppppccpppppc -> 5
cppcppppccpgpppc -> 0