Advertisement
Guest User

желаю окорокову рака

a guest
Apr 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4.  
  5. const int n = 100;
  6. typedef char str[n];
  7. typedef char matrix[n][n];
  8.  
  9. void fillmatrix(matrix& s);
  10. void sent2matrix(str sent, matrix& s);
  11. void search(matrix a, matrix b);
  12. bool match(matrix a, int numa, matrix b, int numb);
  13. int main()
  14. {
  15.  
  16.     matrix s1, s2;
  17.     str sent1, sent2;
  18.     fillmatrix(s1);
  19.     fillmatrix(s2);
  20.     gets_s(sent1);
  21.     gets_s(sent2);
  22.  
  23.     sent2matrix(sent1, s1);
  24.     sent2matrix(sent2, s2);
  25.     printf("\n\nSame words:\n");
  26.     search(s1, s2);
  27.  
  28.  
  29.  
  30. }
  31.  
  32. void fillmatrix(matrix& s) {
  33.     for (int i = 0; i < n; i++)
  34.         for (int j = 0; j < n; j++)
  35.             s[i][j] = '\0';
  36.  
  37. }
  38.  
  39. void sent2matrix(str sent, matrix& s) {
  40.     str strtemp;
  41.     int i = 0, count = 0, num = 0;
  42.     for (int i = 0; i < strlen(sent); i++) {
  43.         if (sent[i] != ' ' && sent[i] != '\0') {
  44.             s[count][num] = sent[i];
  45.             num++;
  46.  
  47.         }
  48.         else if (sent[i] == ' ') {
  49.             s[count][num] = '\0';
  50.             count++;
  51.             num = 0;
  52.         }
  53.     }
  54. }
  55.  
  56. void search(matrix a, matrix b) {
  57.     for (int i = 0; i < n; i++) {
  58.         for (int j = 0; j < n; j++) {
  59.             if (strlen(a[i]) == strlen(b[j]) && match(a,i,b,j) && a[i][0]!='\0') {
  60.                 printf("%s\n", a[i]);
  61.             }
  62.         }
  63.     }
  64. }
  65.  
  66.  
  67. bool match(matrix a, int numa, matrix b, int numb) {
  68.     int count = 0;
  69.     for (int i = 0; i < strlen(a[numa]); i++) {
  70.         if (a[numa][i] == b[numb][i])
  71.             count++;
  72.     }
  73.     if (count == strlen(a[numa]))
  74.         return 1;
  75.     else return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement