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 wurongxin at 2007-03-31 10:45:33 on Problem 1002
#include<iostream.h>
#include<string.h>
#include<stdio.h> 

struct T{
       char ch[8];
       int  t;
};

char match(char c){
        switch(c){
			case 'A': case 'B': case 'C': return '2';
			case 'D': case 'E': case 'F': return '3';
			case 'G': case 'H': case 'I': return '4';
			case 'J': case 'K': case 'L': return '5';
			case 'M': case 'N': case 'O': return '6';
			case 'P': case 'R': case 'S': return '7';
			case 'T': case 'U': case 'V': return '8';
			case 'W': case 'X': case 'Y': return '9';
			default: return c;
		}
}

int main(){
    int count,len,i=0,j,k;
    T str[200000];
    char temp[50],tmpstr[8],pstr[8];
    scanf("%d",&count);
    while(count>0){
        cin>>temp;
        len = strlen(temp);
        for(j=0,k=0;j<len;j++)
          if(temp[j]!='-')  tmpstr[k++]=match(temp[j]);
        if(i==0){
           for(k=0;k<9;k++) str[0].ch[k]=tmpstr[k];
           str[0].t=1;
           i++;
           count--;
           continue;
        }
        for(j=0;j<i;j++){
          if(strcmp(tmpstr,str[j].ch)==0){ 
              str[j].t++;
              count--;
              break;
          }
          else if(strcmp(tmpstr,str[j].ch)<0){
              for(k=i-1;k>=j;k--)  str[k+1]=str[k];
              for(k=0;k<9;k++) str[j].ch[k]=tmpstr[k];
              str[j].t=1;
              i++;
              count--;
              //cout<<i<<endl;
              //cout<<str[j].ch<<" "<<str[j].t<<endl;
              break;
          }
        }
        if(j==i){
           for(k=0;k<9;k++) str[i].ch[k]=tmpstr[k];
           str[i].t=1;
           i++;
           count--;
        }
    }
   bool flag = true;
   for(j=0;j<i;j++){
     if(str[j].t>1){
       flag = false;
       for(k=0;k<8;k++){
          if(k==3) cout<<'-';
          cout<<str[j].ch[k];
       }
       cout<<" "<<str[j].t<<endl;
      }
    }
    if(flag) 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