Advertisement
Soverein

Untitled

Dec 17th, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <string.h>
  4. using namespace std;
  5. int main()
  6. {
  7. char str[] = "random offer consisting of numbers 124324321 2413523 8712390901201390 1233333";
  8. char delimiters[] = " ;.,!\t\n";//розділові знаки
  9. cout << str << endl;
  10. char* curWord = strtok(str, delimiters);//пошук першого слова
  11. char* maxStr = NULL;
  12. int maxNum = 0;
  13. char numbers[] = "0123456789";
  14. if (curWord)
  15. while (curWord)
  16. {
  17. int curNum = 0;
  18. for (int i = 0; curWord[i] != 0; ++i) //підрахунок кількості символів
  19. if (strchr(numbers, curWord[i])) ++curNum;//у першому слові
  20. if (maxStr == NULL || maxStr && (curNum > maxNum))
  21. {
  22. maxStr = curWord;
  23. maxNum = curNum;
  24. }
  25. cout << endl << curWord << ": " << curNum;
  26. curWord = strtok(NULL, delimiters);//пошук наступного слова
  27. }
  28. cout << endl;
  29. if (maxStr) cout << "Max : " << maxStr << "\t";
  30.  
  31. else cout << "Word not found" << endl;
  32. system("pause");
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement