Advertisement
VariableRiw

Length==v2

Mar 21st, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3.  
  4. int main(void)
  5. {
  6. int c, count, len1, flag, nw, status;
  7. setlocale(LC_ALL, "rus");
  8. count = 0; // счёстчик символов в слове
  9. len1 = 0; // длина первого слова
  10. flag = 1; // условие, когда слова одинаковой длины
  11. nw = 0; // количество слов
  12. status = 0; // признак нахождения в слове
  13. printf("Введите строку: \n");
  14. while ((c = getchar()) != '0')
  15. {
  16. if ((c == ' ') || (c == ',') || (c == '\n') || (c == '.') || (c == '\t'))
  17. {
  18. status = 0;
  19. }
  20. else if (status == 0)
  21. {
  22. status = 1;
  23. nw++;
  24. }
  25. if ((c != ' ') && (c != ',') && (c != '\n') && (c != '.') && (c != '\t'))
  26. count++;
  27. else
  28. {
  29. if (len1 == 0)
  30. {
  31. len1 = count;
  32. }
  33. if ((len1 != count)&& (count != 0))
  34. {
  35. flag = 0;
  36. }
  37. count = 0;
  38. }
  39.  
  40. }
  41. if ((len1 != count) && (count != 0))
  42. {
  43. flag = 0;
  44. }
  45. if ((flag == 1) && (nw > 1))
  46. printf("Слова одинаковой длины\n");
  47. else if (nw <= 1)
  48. printf("Введите не менее двух слов\n");
  49. else if (flag == 0)
  50. printf("Слова разной длины\n");
  51. system("pause");
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement