Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

???哪错了????

Posted by samesokko2 at 2006-09-21 02:15:53 on Problem 1318
#include <stdio.h>
#include <string.h>
int main()
{
    char a[100][7], ta[100][7],tta[100][7], x[7]="XXXXXX", c, t[7], f[7];
    int len, i, j, k,l, n[100],ans[100], tn, s1;
    
    k=0;
    while(1)
    {
        scanf("%s", a[k]);
		
		if( strcmp(a[k], x)==0 )
            break;
        len=strlen(a[k]);
        strncpy(ta[k], a[k], 7);
		
        strncpy(tta[k], a[k], 7);
	
        for(i=0; i<len; i++)
        {
            for(j=0; j<len-i-1; j++)
                if(ta[k][j]>ta[k][j+1])
                {
                    c=ta[k][j];
                    ta[k][j]=ta[k][j+1];
                    ta[k][j+1]=c;
                }
        }
	
        n[k]=k;
        k++;
    }
	
	s1=k;
    for(i=0; i<s1; i++)
    {
	
        for(j=0; j<s1-i-1; j++)
            if( strcmp(tta[j], tta[j+1])>0 )
            {
                strncpy(t, tta[j], 7);
                strncpy(tta[j], tta[j+1], 7);
                strncpy(tta[j+1], t, 7);
                
                tn=n[j];
                n[j]=n[j+1];
                n[j+1]=tn;   
            }
    }
	
	
	while(1)
	{
		scanf("%s", f); 
		if( strcmp(f, x)==0 )
            break;
        len=strlen(f);
		for(i=0; i<len; i++)
        {
            for(j=0; j<len-i-1; j++)
                if(f[j]>f[j+1])
                {
                    c=f[j];
                    f[j]=f[j+1];
                    f[j+1]=c;
                }
        }
		k=0;
		for(j=0; j<s1; j++)
		{
			if( strcmp(f, ta[j])==0 )
				ans[k++]=j;
		}
	
		if(k==0)
		{
			printf("NOT A VALID WORD\n");
			printf("******\n");
			continue;
		}
		
		for(j=0; j<k; j++)
		{
			for(l=0; l<k-j-1; l++)
				if(n[ans[l]]>n[ans[l+1]])
				{
					strncpy(t, a[ans[l]], 7);
                    strncpy(a[ans[l]], a[ans[l+1]], 7);
                    strncpy(a[ans[l+1]], t, 7);
					
					tn=n[ans[l]];
                    n[ans[l]]=n[ans[l+1]];
					n[ans[l+1]]=tn;
				}
		}
			
		for(j=0; j<k; j++)
		{
			printf("%s\n", a[ans[j]]);
		}
		printf("******\n");
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator