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

求大神优化,375MS

Posted by Panamera at 2014-04-11 23:32:11 on Problem 1002
#include<stdio.h>
#include<algorithm>
#define MAX_N 26
#define MAX_M 100090
using namespace std;
int num[MAX_M];
int hash[MAX_N]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
int main()
{
    int n;
    //此处数组大小不能开小了,我就是在这上面贡献了几次wrong.
    char s[300]={'\0'};
    scanf("%d",&n);
    getchar();
    for(int i=0;i<n;++i)
    {
        int tmp = 0 ;
        gets(s);
        for(int j=0;s[j];++j)
        {
            if((s[j]>='0'&&s[j]<='9')||(s[j]>='A'&&s[j]<='Y'&&s[j]!='Q'))
                tmp = tmp * 10 + (s[j] <='9' ? s[j] - 48 : hash[s[j]-'A']);
        }
        num[i] = tmp;
    }
    sort(num,num+n);
    num[n] = -1 ;
    bool flag = true;
    for(int i=0,j;i<n;++i)
    {
        if(num[i]!=num[i+1])
            continue;
        for(j=i+1;num[j]==num[i];++j);
        printf("%03d-%04d %d\n",num[i]/10000,num[i]%10000,j-i);
        flag = false;
        i = j - 1;
    }
    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