fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. cin.ignore();
  8.  
  9. vector<int> tab(n);
  10. for (int i = 0; i < n; i++) {
  11. cin >> tab[i];
  12. }
  13. cin.ignore();
  14.  
  15. string k;
  16. getline(cin, k);
  17.  
  18. vector<string> words;
  19. string c;
  20. for (char ch : k) {
  21. if (isalpha(ch)) {
  22. c += ch;
  23. } else {
  24. if (!c.empty()) {
  25. words.push_back(c);
  26. c.clear();
  27. }
  28. }
  29. }
  30. if (!c.empty()) words.push_back(c);
  31.  
  32. for (int i = 0; i < n; i++) {
  33. if (tab[i] == 1) {
  34. int liczba = count(k.begin(), k.end(), ' ');
  35. cout << liczba << " ";
  36. } else if (tab[i] == 2) {
  37. int liczba = 0;
  38. if (isdigit(k[0])) liczba++;
  39. for (size_t j = 1; j < k.size(); j++) {
  40. if (isdigit(k[j]) && !isdigit(k[j - 1])) {
  41. liczba++;
  42. }
  43. }
  44. cout << liczba << " ";
  45. } else if (tab[i] == 3) {
  46. cout << words.size() << " ";
  47. } else if (tab[i] == 4) {
  48. int z = 0;
  49. bool oski = true;
  50. for (char ch : k) {
  51. if (oski && ch == '.') {
  52. z++;
  53. oski = false;
  54. } else if (isalpha(ch)) {
  55. oski = true;
  56. }
  57. }
  58. cout << z << " ";
  59. } else if (tab[i] == 5) {
  60. int d = 0;
  61. for (const string& word : words) {
  62. bool bajtek = true;
  63. int a = word.size();
  64. for (int j = 0; j < a / 2; j++) {
  65. if (tolower(word[j]) != tolower(word[a - j - 1])) {
  66. bajtek = false;
  67. break;
  68. }
  69. }
  70. if (bajtek) {
  71. d++;
  72. }
  73. }
  74. cout << d << " ";
  75. }
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty