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

1002,超时了,求大牛们解释下哪里弄复杂了。。。

Posted by hl520 at 2011-02-19 23:23:29 on Problem 1002
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<algorithm>
void fun(char s[100])
{
    int i,j=0;
    char c[100]={'\0'};
    c[3]='-';
    for(i=0;s[i]!='\0';i++)
    {
        if(s[i]>='0'&&s[i]<='9')
        {
            c[j++]=s[i];
        }
        else
        {
            switch(s[i])
           {
            case('A'):c[j++]='2';break;
            case('B'):c[j++]='2';break;
            case('C'):c[j++]='2';break;
            case('D'):c[j++]='3';break;
            case('E'):c[j++]='3';break;
            case('F'):c[j++]='3';break;
            case('G'):c[j++]='4';break;
            case('H'):c[j++]='4';break;
            case('I'):c[j++]='4';break;
            case('J'):c[j++]='5';break;
            case('K'):c[j++]='5';break;
            case('L'):c[j++]='5';break;
            case('M'):c[j++]='6';break;
            case('N'):c[j++]='6';break;
            case('O'):c[j++]='6';break;
            case('P'):c[j++]='7';break;
            case('R'):c[j++]='7';break;
            case('S'):c[j++]='7';break;
            case('T'):c[j++]='8';break;
            case('U'):c[j++]='8';break;
            case('V'):c[j++]='8';break;
            case('W'):c[j++]='9';break;
            case('X'):c[j++]='9';break;
            case('Y'):c[j++]='9';break;
            default:break;
            }
        }
        if(j==3) j++;
    }
    memcpy(s,c,sizeof(c));
}
typedef struct num
{
    char a[10];
    int m;
}num;
bool cmp(num x,num y)
{
    return(strcmp(x.a,y.a)<0);
}
using namespace std;
int main()
{
    int n,i,flag=0,j;
    char s[100],c,*p;
    num *x;
    scanf("%d",&n);c=getchar();
    x=(num *)malloc(sizeof(num)*n);
    while(n--)
    {
        gets(s);p=s;fun(p);
        for(i=0;i<flag;i++)
        {
            if(strcmp(p,x[i].a)==0)
            {
              (x[i].m)++;break;
            }
        }
        if(i==flag) {x[flag].m=1;memcpy(x[flag].a,p,sizeof(x[flag].a));flag++;}
    }
    sort(x,x+flag,cmp);
    for(i=0,n=0;i<flag;i++)
    {
        if(x[i].m>=2)
        {
            n++;
            printf(x[i].a);
            printf(" %d\n",x[i].m);
        }
    }
    if(n==0) printf("No duplicates.");
    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