Untitled

 avatar
unknown
plain_text
4 years ago
1.5 kB
53
Indexable
#include<stdio.h>
#include<string.h>
void ss(char *s)
{
	int i;
	int j;
	int n = strlen(s);
	for(i = 0;i<n-1;i++)
	{
		for(j = n-1;j>i;j--) 
		{
			if(s[j] < s[j-1])
			{
				char k = s[j-1];
				s[j-1] = s[j];
				s[j] = k;
			}
		}
	}
}


int main()
{   
    char s1[100];
    char s2[100];
    char c1[100][100], c2[100][100];
    gets(s1);
    gets(s2);
    char *cpy;
    int i = 0;
    cpy = strtok(s1, " ");
    while(cpy != '\0')
    {
    	strcpy(c1[i], cpy);
    	cpy = strtok(NULL, " ");
    	i++;
	}
	int count1 = i;
    i = 0;
    cpy = strtok(s2, " ");
    while(cpy != '\0')
    {
    	strcpy(c2[i], cpy);
    	cpy = strtok(NULL, " ");
    	i++;
	}
	int count2 = i;
    int j = 0;
    cpy = "-1";
 
    for(i = 0;i<count1;i++)
    {
    	for(j = 0;j<count2;j++)
    	{
    		if(strcmp(c1[i],c2[j]) == 0)
    		{
    			strcpy(c1[i],cpy);
    		
    			break;
			}
		}
	}
	
	j = 0;
	char c3[100][100];
    for(i = 0;i<count1;i++)
    {  
    	if(strcmp(c1[i],cpy) != 0)
    	{
    		strcpy(c3[j],c1[i]);
    		ss(c3[j]);
    		j++;
		}
	}

	int h = 0;
	char c4[100][100];
    for(i = 0;i<j;i++)
    {
    	for(h = i+1;h<j;h++)
    	{
    		if(strcmp(c3[i],c3[h]) == 0)
    		{
    			strcpy(c3[h],cpy);
			}
		}
	}
	
	h =0;
	for(i = 0;i<j;i++)
    {  
    	if(strcmp(c3[i],cpy) != 0)
    	{
         	strcpy(c4[h],c3[i]);
         	h++;
		}
	}
	
	for(i = 0;i<h;i++)
	{
		printf("%s ",c4[i]);
	}
	return 0;
}
Editor is loading...