TẬP TỪ RIÊNG CỦA HAI XÂU 1 - PTIT CODE
Made by HOÀNG BÁ THANHunknown
plain_text
4 years ago
1.2 kB
5
Indexable
#include<stdio.h> #include<string.h> int m = 0, n = 0; void mang_S1(char s1[], char S1[][50]){ char *p = strtok(s1," "); while(p!=NULL){ int kt = 1; for(int i = 0; i < m; i++) if(strcmp(S1[i],p)==0) kt = 0; if(kt == 1){ strcpy(S1[m],p); m = m + 1; } p = strtok(NULL," "); } // for(int i = 0; i < m; i++) // printf("S1[%d] = %s\n", i, S1[i]); } void mang_S2(char s2[], char S2[][50]){ char *p = strtok(s2," "); while(p!=NULL){ strcpy(S2[n],p); n = n + 1; p = strtok(NULL," "); } } void sapxep(char S1[][50]){ for(int i = 0; i < m; i++){ for(int j = i + 1; j < m; j++) if(strcmp(S1[i],S1[j])>0){ char tmp[50]; strcpy(tmp,S1[i]); strcpy(S1[i],S1[j]); strcpy(S1[j],tmp); } } // for(int i = 0; i < m; i++) // printf("S1[%d] = %s\n", i, S1[i]); } void xuly(char s1[101], char s2[101], char S1[100][50], char S2[100][50]){ for(int i = 0; i < m; i++){ int kt = 1; for(int j = 0; j < n; j++){ if(strcmp(S1[i],S2[j])==0) kt = 0; } if(kt == 1) printf("%s ", S1[i]); } } int main(){ char s1[101], s2[101], S1[100][50], S2[100][50]; int m = 0, n = 0; gets(s1); mang_S1(s1,S1); gets(s2); mang_S2(s2,S2); sapxep(S1); xuly(s1,s2,S1,S2); }
Editor is loading...