fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. void hhh() {
  6. ios_base::sync_with_stdio(0);
  7. cin.tie(0);
  8. }
  9.  
  10. int check( string &s) {
  11. // chu cai dau tien uppercase
  12. //i a m
  13. // m a i
  14. if( islower(s[0])) return 0 ;
  15. transform(s.begin(), s.end(), s.begin(), ::tolower);
  16. string m1 = "mai";
  17. string m2 = "iam";
  18. int idex1 = 0 ;
  19. int idex2 = 0 ;
  20.  
  21. for( int i = 0 ; i < s.size() ; i++ ) {
  22. if( s[i] == m1[idex1]) {
  23.  
  24. ++idex1;
  25. }
  26. if( s[i] == m2[idex2]) {
  27.  
  28. ++idex2;
  29. }
  30. if( idex1 == 3 || idex2 == 3) return 1;
  31. }
  32. return 0;
  33. }
  34. int main() {
  35. hhh();
  36. int t;
  37. cin >> t;
  38. while (t--) {
  39. cin.ignore();
  40. string test;
  41. int cnt = 0 ;
  42. getline( cin, test);
  43.  
  44. string word;
  45.  
  46. stringstream ss(test);
  47.  
  48. while( ss >> word) {
  49. if( check(word)) {
  50. ++cnt;
  51. }
  52. }
  53. cout << cnt<< '\n';
  54. }
  55. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty