Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- const int n = 100;
- typedef char str[n];
- typedef char matrix[n][n];
- void fillmatrix(matrix& s);
- void sent2matrix(str sent, matrix& s);
- void search(matrix a, matrix b);
- bool match(matrix a, int numa, matrix b, int numb);
- int main()
- {
- matrix s1, s2;
- str sent1, sent2;
- fillmatrix(s1);
- fillmatrix(s2);
- gets_s(sent1);
- gets_s(sent2);
- sent2matrix(sent1, s1);
- sent2matrix(sent2, s2);
- printf("\n\nSame words:\n");
- search(s1, s2);
- }
- void fillmatrix(matrix& s) {
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- s[i][j] = '\0';
- }
- void sent2matrix(str sent, matrix& s) {
- str strtemp;
- int i = 0, count = 0, num = 0;
- for (int i = 0; i < strlen(sent); i++) {
- if (sent[i] != ' ' && sent[i] != '\0') {
- s[count][num] = sent[i];
- num++;
- }
- else if (sent[i] == ' ') {
- s[count][num] = '\0';
- count++;
- num = 0;
- }
- }
- }
- void search(matrix a, matrix b) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (strlen(a[i]) == strlen(b[j]) && match(a,i,b,j) && a[i][0]!='\0') {
- printf("%s\n", a[i]);
- }
- }
- }
- }
- bool match(matrix a, int numa, matrix b, int numb) {
- int count = 0;
- for (int i = 0; i < strlen(a[numa]); i++) {
- if (a[numa][i] == b[numb][i])
- count++;
- }
- if (count == strlen(a[numa]))
- return 1;
- else return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement