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 15310320305 at 2016-05-06 13:39:27 on Problem 1002
In Reply To:wa的同学看一下 Posted by:913106840325 at 2014-07-09 15:46:43
我之前是字符数组开小了,总WA,,看了你这个后我也加到了300,AC了!!!
借鉴了其它大神的思路


#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
int n=0;
int m=0;
int stream(int n){
     int s = 1000000;
     for(int i=0;i<m;i++)
        s=s/10;
     m++;
     return s*n;
}
int str[100005];
int main(){
    int t;
      scanf("%d",&t);
      getchar();
      while(t--)
      {

          m=0;
          char s[300];
          int ss=0;
          gets(s);
          for(int i=0;i<strlen(s);i++)
          {
              if(s[i]>='0'&&s[i]<='9'){int h = s[i]-'0';ss+=stream(h);}
              else if(s[i]=='A'||s[i]=='B'||s[i]=='C')ss+=stream(2);
              else if(s[i]=='D'||s[i]=='E'||s[i]=='F')ss+=stream(3);
              else if(s[i]=='G'||s[i]=='H'||s[i]=='I')ss+=stream(4);
              else if(s[i]=='J'||s[i]=='K'||s[i]=='L')ss+=stream(5);
              else if(s[i]=='M'||s[i]=='N'||s[i]=='O')ss+=stream(6);
              else if(s[i]=='P'||s[i]=='R'||s[i]=='S')ss+=stream(7);
              else if(s[i]=='T'||s[i]=='U'||s[i]=='V')ss+=stream(8);
              else if(s[i]=='W'||s[i]=='X'||s[i]=='Y')ss+=stream(9);
          }
             str[n++]= ss;
      }
      sort(str,str+n);
           int num=1;
           int flag=0;
           for(int i=0;i<n-1;i++){
                  while(str[i]==str[i+1]){
                    num++;
                    i++;
                    flag=1;
                  }
                    if(num>1){
                        printf("%0.3d-%0.4d %d\n",str[i]/10000,str[i]%10000,num);
                        num=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