Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #define nombredesmots 5
- int main()
- {
- char* a[10];
- char* b[10];
- int i,j,k[10],index=0,compteur[10];
- //on the next 10 rows the input will be initiated as two arrays with words
- for(i=0;i<5;i++)
- {
- a[i]=(char*) malloc(10);
- scanf("%s",a[i]);
- }
- for(i=0;i<5;i++)
- {
- b[i]=(char*) malloc(10);
- scanf("%s",b[i]);
- }
- /* starting to compare every word with every to establish
- which are identical and take the position from the first array and lenght of the word as well
- */
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- if(strcmp(a[i],b[j])==0)
- {
- k[index]=i;
- compteur[index]=strlen(a[i]);
- index++;
- }
- }
- }
- int max,position;
- //check if the counter array is empty and check which word of the equals has the biggest lenght and print it on the console
- if(index==-1);
- else
- {
- max=compteur[0];
- for(i=1;i<index;i++)
- {
- if(max<compteur[i]) {max=compteur[i];position=i;}
- }
- printf("%s",a[k[position]]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement