Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
麻烦高人指点一下,为什么老是RE#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; const int N=50; const int MAX=100; int cmp( const void *a, const void *b); void search(char str[MAX][N], int num); int main() { int num=0; char str[MAX][N]={'\0'}; cin>>num; getchar(); for (int i=0; i<num; ++i) { int j=0; str[i][j]=getchar(); while ( str[i][j]!='\n') { switch (str[i][j]) { case '-':break; case 'A': case 'B': case 'C':str[i][j]='2';break; case 'D': case 'E': case 'F':str[i][j]='3';break; case 'G': case 'H': case 'I':str[i][j]='4';break; case 'J': case 'K': case 'L':str[i][j]='5';break; case 'M': case 'N': case 'O':str[i][j]='6';break; case 'P': case 'R': case 'S':str[i][j]='7';break; case 'T': case 'U': case 'V':str[i][j]='8';break; case 'W': case 'X': case 'Y':str[i][j]='9';break; } ++j; if ( str[i][j-1]=='-' ) --j; if ( j==3 ) { str[i][j]='-'; ++j; } str[i][j]=getchar(); if ( str[i][j]=='\n' ) { str[i][j]='\0'; break; } } } qsort( str, num, N, cmp); search(str,num); getchar(); return 0; } void search(char str[MAX][N],int num) { int number=1; int flag=0; for (int i=1; i<num; ++i) { if ( strcmp(str[i-1],str[i]) == 0 ) { number++; continue; } else if ( number!=1 ) { cout<<str[i-1]<<' '<<number<<endl; flag=1; } number=1; } if ( flag==0 ) cout<<"No duplicates."<<endl; } int cmp( const void *a,const void *b) { return strcmp( (char*)a, (char*)b ); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator