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 yyii1111 at 2012-10-05 18:30:19 on Problem 1002
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <string>
#define foreach(it,v) for (__typeof((v).begin()) it = (v).begin();it != (v).end();++it)

using namespace std;

map<int,int> mym;
char s[1000];
char cc[180];

void init()
{
    for(int i='0'; i<='9'; i++) cc[i] = i - '0';
    for(int i='A'; i<='P'; i++) cc[i] = (i - 'A') / 3 + 2;
    for(int i='R'; i<='Y'; i++) cc[i] = (i - 'B') / 3 + 2;
}

void gao(char *s)
{
    int tmp = 0;
    for(int i=0; s[i]; ++i)
        if(s[i] != '-')
            tmp = tmp*10+cc[s[i]];
    if(mym.find(tmp) == mym.end())
        mym[tmp] = 1;
    else
        ++ mym[tmp];
}

int main()
{
    init();
    int n;
    scanf("%d", &n);
    mym.clear();
    for(int i=0; i<n; i++)
    {
        scanf("%s", s);
        gao(s);
    }
    bool have = false;
    foreach(it, mym) {
        if(it->second > 1) {
            have = true;
            printf("%03d-%04d %d\n",it->first/10000, it->first%10000, it->second);
        }
    }
    if(!have) puts("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