Advertisement
Soverein

Untitled

Dec 16th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char str[] = "A computer is a device that processes data according to a set of instructions known as a program";
  10. char delimiters[] = " ;.,!\t\n";
  11. cout << str << endl;
  12. char* curWord = strtok(str, delimiters);
  13. char* maxStr = 0;
  14. int maxNum = 0;
  15. int i = 0;
  16. char consonants[] = "cmptrsdvhngfkwm";
  17. while (curWord != NULL)
  18. {
  19. int curNum = 0;
  20. for (i = 0; curWord[i] != 0; ++i)
  21. {
  22. if (strchr(consonants, curWord[i])) ++curNum;
  23. }
  24. if (maxNum < curNum)
  25. {
  26. maxNum = curNum;
  27. maxStr = curWord;
  28. }
  29. printf("\n%s", curWord);
  30. cout << ": " << curNum;
  31. curWord = strtok(NULL, delimiters);
  32. }
  33. cout << endl;
  34. cout << "The most consonant letters has a word: " << maxStr << ":\t " << maxNum << endl;
  35. system("pause");
  36. return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement