引用
AC的代码
https://blog.csdn.net/liangzhaoyang1/article/details/51056005
正文
自己写的时候无语了,死活都是WA,也找不到测试用例,先把错误的代码放在这,期待以后或者有缘人(大佬)能看看错误
代码
#include<iostream>
using namespace std;
int N;
long nums[100009];
int numsi=0; //当前多少个
void getin() {
char in[1005];
cin>>in;
int temp=0;
for(int i=0; in[i]; i++) {
if(in[i]=='-') {
continue;
} else if(in[i]<='Z'&&in[i]>='A') {
switch(in[i]) {
case 'A':
temp=temp*10+2;
break;
case 'B':
temp=temp*10+2;
break;
case 'C':
temp=temp*10+2;
break;
case 'D':
temp=temp*10+3;
break;
case 'E':
temp=temp*10+3;
break;
case 'F':
temp=temp*10+3;
break;
case 'G':
temp=temp*10+4;
break;
case 'H':
temp=temp*10+4;
break;
case 'I':
temp=temp*10+4;
break;
case 'J':
temp=temp*10+5;
break;
case 'K':
temp=temp*10+5;
break;
case 'L':
temp=temp*10+5;
break;
case 'M':
temp=temp*10+6;
break;
case 'N':
temp=temp*10+6;
break;
case 'O':
temp=temp*10+6;
break;
case 'P':
temp=temp*10+7;
break;
case 'R':
temp=temp*10+7;
break;
case 'S':
temp=temp*10+7;
break;
case 'T':
temp=temp*10+8;
break;
case 'U':
temp=temp*10+8;
break;
case 'V':
temp=temp*10+8;
break;
case 'W':
temp=temp*10+9;
break;
case 'X':
temp=temp*10+9;
break;
case 'Y':
temp=temp*10+9;
break;
default:
break;
}
} else if(in[i]<='9'&&in[i]>='0') {
temp=temp*10+in[i]-'0';
}
}
nums[numsi++]=temp;
}
void numsquicksort(int a, int b){ // 对nums数组调用快速排序
if(a>=b){
return ;
}
int i=a;
int j=b;
int tag=a;
int temp;
while(i<j){
while(nums[j]>nums[tag]&&j>i) j--;
if(i<j){
temp=nums[tag];
nums[tag]=nums[j];
nums[j]=temp;
tag=j;
j--;
}
while(nums[i]<nums[tag]&&i<j) i++;
if(i<j){
temp=nums[tag];
nums[tag]=nums[i];
nums[i]=temp;
tag=i;
i++;
}
}
numsquicksort(a, tag-1);
numsquicksort(tag+1, b);
}
void output(int num, int copy){
int kk=1000000;
for(int i=0;i<7;i++){
int tmp=num/kk;
num%=kk;
kk/=10;
cout<<tmp;
if(i==2) cout<<"-";
}
cout<<" "<<copy<<endl;
}
void getout() { //输出并输出重复个数
// int temp=0;
// int count=0;
// int oldcount=0;
// int numtemp=-1;
int i=0;
int temp=0;
int copy;
while(i<N){
// if(nums[i]!=temp){
// // cout<<nums[i]<<endl;
// oldcount=count;
// count=1;
// temp=nums[i];
// }else{
// count++;
// numtemp=nums[i];
// }
// if(count==1&&numtemp!=-1){
//
// }
if(nums[i]!=nums[i+1]){
i++;
continue;
} else{
temp=nums[i];
copy=0;
while(nums[i]==temp) {
copy++; i++;
}
}
output(temp, copy);
}
}
void output2(){
cout<<endl<<"nums:"<<endl;
for(int i=0;i<N;i++){
cout<<nums[i]<<endl;
}
cout<<endl;
}
bool ifchong(){
int flag=0;
for(int i=0;i<N;i++){
if(nums[i]==nums[i+1]){
flag=1;
return 1;
}
}
return 0;
}
int main() {
cin>>N; //总个数
for(int i=0;i<N;i++){
getin();
}
//output2();
numsquicksort(0, N-1);
if(!ifchong()){ //如果没有重复
cout<<"No duplicates."<<endl;
}else{
// cout<<"wuchongfu"<<endl;
getout();
//output2();
}
return 0;
}