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

Re:郁闷,偷懒用STL不行啊,超时.难道这道题不能用STL么

Posted by lshguang89 at 2007-11-03 18:57:33 on Problem 1002
In Reply To:Re:郁闷,偷懒用STL不行啊,超时.难道这道题不能用STL么 Posted by:badming at 2007-10-13 12:20:14
#include <cstdio>
#include <map>
#include <string>
using namespace std;

int main()
{
    map<char,string> replace;
    map<string,int> result;
    for (int r='A';r<='P';r++)
       replace[r]=(r-65)/3+50; 
    for (int m='R';m<='Y';m++)
       replace[m]=(m-66)/3+50; 
   
    int num;
    int flag=0;
    string temp;
    scanf("%d",&num);
    for (int i=1;i<=num;i++)
    {
        scanf("%s",temp);
        for(int j=0;j<temp.length();j++)
                if (temp[j]=='-')
                {
                    temp.erase(j,1);
                    j--;
                }
        for(unsigned s=0;s<temp.length();s++)
            if (temp[s]<'Z' &&  temp[s]>='A' )
            {
                string cur=replace[temp[s]];
                temp.replace(s,1,cur);
            }
        temp.insert(3,"-");
        if (++result[temp]>=2 && flag==0)
            flag=1;
    }
    if (flag==0)
        printf("%s","No duplicates.\n");
    else 
        for(map<string,int>::iterator it=result.begin();it!=result.end();it++)
            if (it->second!=1)
                printf("%s %d\n",it->first,it->second);
}

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