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

TLE,请大家看下,哪儿慢下来的,一直超时。谢谢

Posted by fyhue at 2007-08-08 12:20:49 on Problem 1002
#include <stdio.h>
#include <string.h>
char str[100000][100], s[100];
int main()
{
    int n, i, j, k, r, a[50000], count, flag=1;
    char ch;
    while(scanf("%d",&n)==1)
    {
        i=0;
        count=0;
		getchar();
        while(i<n)
        {
            j=0;
            while(1)
            {
                if(j==3)
                {
                    s[j]='-';
                    j++;
                }
                ch=getchar();
                if(ch>='A'&&ch<='Y')
                {
                    if(ch<='P')
						ch=50+(ch-'A')/3;
					else if(ch=='R'||ch=='S')
						ch='7';
					else if(ch=='T'||ch=='U'||ch=='V')
						ch='8';
					else
						ch='9';
                }
                else if(ch=='-')
                {
                    continue;
                }
                else if(ch==10)
                {
                    break;
                }
                s[j]=ch;
                j++;
            }
            s[8]='\0';
            if(count)
            {
				for(k=0; k<count; k++)
				{
					int t=strcmp(str[k], s);
					if(t==0)
					{
						a[k]++;
						break;
					}
					else if(t>0)
					{
						r=count;
						while(r>k)
						{
							strcpy(str[r], str[r-1]);
							a[r]=a[r-1];
							r--;
						}
						strcpy(str[k], s);
						a[k]=1;
						count++;
						break;
					}
					else
					{
						if(k==count-1)
						{
							strcpy(str[count], s);
							a[count]=1;
							count++;
							break;
						}
					}
				}
            }
            else
            {
                strcpy(str[0], s);
                a[0]=1;
                count++;
            }
            i++;
        }
        for(k=0; k<count; k++)
        {
            if(a[k]>1)
            {
                printf("%s %d\n", str[k], a[k]);
                flag=0;
            }
        }
        if(flag)
            printf("No duplicates.\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