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

一直WA,各种可能的数据都测试了,求指点

Posted by lzddlut at 2012-10-14 08:50:50 on Problem 1002
#include <iostream>
#include <string>

using namespace std;

string formtranslate(string str)
{
     char res[20];
     int j=0;
     for(int i=0;i<str.length();i++)
     {
         if(j==3)
         {
             res[j++]='-';
         }
         switch(str[i])
         {
              case   'A':;
              case   'B':;
              case   'C':res[j++]='2';break;
              case   'D':;
              case   'E':;
              case   'F':res[j++]='3';break;
              case   'G':;
              case   'H':;
              case   'I':res[j++]='4';break;
              case   'J':;
              case   'K':;
              case   'L':res[j++]='5';break;
              case   'M':;
              case   'N':;
              case   'O':res[j++]='6';break;
              case   'P':;
              case   'R':;
              case   'S':res[j++]='7';break;
              case   'T':;
              case   'U':;
              case   'V':res[j++]='8';break;
              case   'W':;
              case   'X':;
              case   'Y':res[j++]='9';break;
              case   'Q':;
              case   'Z':;
              case   '-':;break;
              default : res[j++]=str[i];
         }
     }
     res[j++]='\0';
     return res;
}
void quiksort(string  arr[],int p,int q)
{
    if(q>p)
    {
        int j=p-1;
        string temp;
        for(int i=p;i<q;i++)
        {
            if(arr[i]<arr[q])
            {
                j++;
                if(i>j)
                {
                     temp=arr[i];
                     arr[i]=arr[j];
                    arr[j]=temp;
                }
             }
         }
         j++;
         temp=arr[j];
         arr[j]=arr[q];
         arr[q]=temp;
         quiksort(arr,p,j-1);
         quiksort(arr,j+1,q);
    }
}
int main()
{
    //cout << "Hello world!" << endl;
    int count;
    int t=0;
    cin>>count;
    string arr[1000];
    string temp;
    for(int i=0;i<count;i++)
    {
        cin>>temp;
        arr[i]=formtranslate(temp);
    }

    quiksort(arr,0,count-1);

    int num=1;
    for(int i=0;i<count;i++)
    {
        if(i>0&&arr[i]==arr[i-1])
        {
            num++;

        }
        if(i==count-1 || i<count-1 && arr[i] != arr[i+1])
        {
            if(num>1)
            {
                cout<<arr[i]<<" "<<num<<endl;
                t++;
            }
            num=1;
        }

    }
    if(t==0)
        {
            cout<<"No duplicates. "<<endl;
        }
    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