| ||||||||||
| 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 <stdio.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
//我的答案没有任何问题的
struct type{ //储存电话号码类型
char chac[20]; //号码
int duptime; //重复的次数
};
int num; //输入的号码的个数
char s[100][50]; //用char存储起来,方便转换格式
type t[100]; //初始化100个
int typenum=0; //不重复的电话号码的个数
void handle(const char *c){ //处理字符串
int len=strlen(c);
char tmp[8];
int k=0;
for(int j=0;j<len;j++){
if(c[j]=='A'||c[j]=='B'||c[j]=='C'||c[j]=='2'){
tmp[k++]='2';
}else if(c[j]=='D'||c[j]=='E'||c[j]=='F'||c[j]=='3'){
tmp[k++]='3';
}else if(c[j]=='G'||c[j]=='H'||c[j]=='I'||c[j]=='4'){
tmp[k++]='4';
}else if(c[j]=='J'||c[j]=='K'||c[j]=='L'||c[j]=='5'){
tmp[k++]='5';
}else if(c[j]=='M'||c[j]=='N'||c[j]=='O'||c[j]=='6'){
tmp[k++]='6';
}else if(c[j]=='P'||c[j]=='R'||c[j]=='S'||c[j]=='7'){
tmp[k++]='7';
}else if(c[j]=='T'||c[j]=='U'||c[j]=='V'||c[j]=='8'){
tmp[k++]='8';
}else if(c[j]=='W'||c[j]=='X'||c[j]=='Y'||c[j]=='9'){
tmp[k++]='9';
}else{
if(c[j]=='0')tmp[k++]='0';
else if(c[j]=='1')tmp[k++]='1';
else continue;
}
}
tmp[k]='\0';
if(typenum==0){
strcpy(t[typenum].chac,tmp);
t[typenum].duptime=1;
typenum++;
}else{
bool test=false;
for(int i=0;i<typenum;i++){
if(strcmp(t[i].chac,tmp)==0){
t[i].duptime++;
test=true;
break;
}else{
continue;
}
}
if(!test){
strcpy(t[typenum].chac,tmp);
t[typenum].duptime=1;
typenum++;
}
}
}
void print(){ //打印出来
bool test=false;
for(int j=0;j<typenum;j++){
if(t[j].duptime!=1){
test=true;
for(int i=0;i<7;i++){
if(i==3)printf("-%c",t[j].chac[i]);
else printf("%c",t[j].chac[i]);
}
printf(" %d\n",t[j].duptime);
}
}
if(!test)cout<<"No duplicates."<<endl;
}
int cmp(const void * a1,const void * a2){ //快速排序
type p1=*(type *)a1;
type p2=*(type *)a2;
return strcmp(p1.chac,p2.chac);
}
void main(){
scanf("%d",&num);
for(int i=0;i<num;i++){
scanf("%s",s[i]);
handle(s[i]);
}
qsort(t,typenum,sizeof(type),cmp);
print();
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator