fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. int func(char *s1, char *s2) {
  8. int i;
  9. int l1 = strlen(s1);
  10. int l2 = strlen(s2);
  11. if (l1 > l2) l1 = l2;
  12. l2 = 0;
  13. for (i = 0; i < l1; i++, s1++, s2++)
  14. if (*s1 == *s2) {
  15. l2++;
  16. if (l2 > 1) return 1;
  17. }
  18. return 0;
  19. }
  20.  
  21. char *getword(char *src, char *dst) {
  22. int l1 = strlen(src);
  23. // пропускаем пробелы и всяк символы кроме цифрь и букви
  24. while (*src && !(isalnum(*src))) src++;
  25. while (*src && isalnum(*src)) {
  26. *dst = *src;
  27. src++; dst++;
  28. }
  29. *dst = '\0';
  30. return src;
  31. }
  32.  
  33. int main() {
  34. char text[] = "hello salut begin rodjer green ground hellboy jorjia";
  35. int count = 0;
  36. char *words[30];
  37. char dest[100];
  38. char *p;
  39. p = text;
  40. cout << text << endl;
  41. while (*p) {
  42. p = getword(p, dest);
  43. words[count] = new char[strlen(dest)+1];
  44. strcpy(words[count], dest);
  45. count++;
  46. }
  47.  
  48. cout << "Slova imeushie bolee 2h sovp\n";
  49. for (int x = 0; x < count-1; x++)
  50. for (int y = x+1; y < count; y++) {
  51. if (func(words[x], words[y])) {
  52. cout << words[x] << " " << words[y] << endl;
  53. }
  54. }
  55.  
  56. for (int i = 0; i < count; i++)
  57. delete [] words[i];
  58.  
  59. return 0;
  60. }
  61.  
  62.  
Success #stdin #stdout 0s 3276KB
stdin
banana mk
stdout
hello salut begin rodjer green ground hellboy jorjia
Slova imeushie bolee 2h sovp
hello hellboy
rodjer jorjia
green ground