| ||||||||||
| 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 | |||||||||
不知为什么我的程序总是runtime error大家给看一下#include<iostream>
#include<string.h>
using namespace std;
void swap(char *p1,char *p2)
{
char p[70];
strcpy(p,p1);
strcpy(p1,p2);
strcpy(p2,p);
}
void print(char *p,int n)
{
for(int i=0;i<7;i++)
{
cout<<p[i];if(i==2) cout<<'-';
}
cout<<' '<<n<<endl;
}
int main()
{
int n;
while( cin>>n){
char p[1000][70];cin.get();
int num[10];
for(int ui=0;ui<100;ui++)
num[ui]=0;
int k=0;
for(int i=0;i<n;i++)
{
char p1[70];
char c;
int t=0;
while(cin.get(c),c!='\n')
{
switch(c)
{
case '0':p1[t++]='0';break;
case '1':p1[t++]='1';break;
case 'A':
case 'B':
case 'C':
case '2':p1[t++]='2';break;
case 'D':
case 'E':
case 'F':
case '3':p1[t++]='3';break;
case 'G':
case 'H':
case 'I':
case '4':p1[t++]='4';break;
case 'J':
case 'K':
case 'L':
case '5':p1[t++]='5';break;
case 'M':
case 'N':
case 'O':
case '6':p1[t++]='6';break;
case 'P':
case 'R':
case 'S':
case '7':p1[t++]='7';break;
case 'T':
case 'U':
case 'V':
case '8':p1[t++]='8';break;
case 'W':
case 'X':
case 'Y':
case '9':p1[t++]='9';break;
}
}
p1[t]=0;
int flag=0;int j=0;
if (!i) {strcpy(p[0],p1),num[k++]=1;}
else{
for(int y=0;y<k;y++)
{
if ((j==0)&&strcmp(p[y],p1)>0){flag=y;j=1;break;}
if (!strcmp(p[y],p1))
{
flag=-1;
num[y]++;
break;
}
}
if(flag!=-1) {if(j){strcpy(p[k],p1);num[k]=1;swap(p[flag],p[k]);swap(num[flag],num[k++]);}else {strcpy(p[k],p1);num[k++]=1;}}}
}
int j=0;
for(int q=0;q<k;q++)
if (num[q]>1) {j++;print(p[q],num[q]);}
if(!j) cout<<"No duplicates"<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator