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 heia at 2014-08-30 19:48:24 on Problem 1002
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <iostream>
using namespace std;
map<string,int>re;
map<string,int>::iterator it;
struct N
{
    char s[105];
    char str[15];
}num[100005];
int main()
{
    freopen("in.txt","r",stdin);
    int n;
    while(scanf("%d",&n)!=EOF){
        re.clear();
        for(int i=0;i<n;i++){
            scanf("%s",num[i].s);
            int k=0;
            for(int j=0;j<strlen(num[i].s);j++){
                if(num[i].s[j]>='0'&&num[i].s[j]<='9')
                    num[i].str[k++]=num[i].s[j];
                else if(num[i].s[j]>='A'&&num[i].s[j]<='Z'){
                    switch(num[i].s[j]){
                    case 'A':case 'B':case 'C':num[i].str[k++]='2';break;
                    case 'D':case 'E':case 'F':num[i].str[k++]='3';break;
                    case 'G':case 'H':case 'I':num[i].str[k++]='4';break;
                    case 'J':case 'K':case 'L':num[i].str[k++]='5';break;
                    case 'M':case 'N':case 'O':num[i].str[k++]='6';break;
                    case 'P':case 'R':case 'S':num[i].str[k++]='7';break;
                    case 'T':case 'U':case 'V':num[i].str[k++]='8';break;
                    case 'W':case 'X':case 'Y':num[i].str[k++]='9';break;
                    }
                }
                if(k==3)
                    num[i].str[k++]='-';
            }
            num[i].str[k]='\0';
            re[num[i].str]++;
        }
        int flag=0;
        for(it=re.begin();it!=re.end();it++)
            if(it->second>1){
                cout<<it->first<<' '<<it->second<<endl;
                flag=1;
            }
        if(flag==0)
            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