POJ 1002。。。作死的答案错误。。。我自己弄了好几组测试数据都是正确的
#include<stdio.h>#include<stdlib.h>#include<math.h>structdianhua{inttel;inttotel;};ch...
#include <stdio.h>
#include<stdlib.h>
#include <math.h>
struct dianhua
{
int tel;
int totel;
};
char tihuan(char c)
{
if (c>='0'&&c<='9') return '1';
if ((c=='A')||(c=='B')||(c=='C')) return '2';
if ((c=='D')||(c=='E')||(c=='F')) return '3';
if ((c=='G')||(c=='H')||(c=='I')) return '4';
if ((c=='J')||(c=='K')||(c=='L')) return '5';
if ((c=='M')||(c=='N')||(c=='O')) return '6';
if ((c=='P')||(c=='R')||(c=='S')) return '7';
if ((c=='T')||(c=='U')||(c=='V')) return '8';
if ((c=='W')||(c=='X')||(c=='Y')) return '9';
return '0';
}
int chuli(char *p)
{
char c,*q,*p0=p;
int n=0,i;
while (*p!='\0')
{
c=tihuan(*p);
if(c=='1')
{
p++;
continue;
}
else if(c=='0')
{
q=p;
while(*q!='\0')
{
*q=*(q+1);
q++;
}
p--;
}
else
{
*p=c;
}
p++;
}
for (i=0;i<=6;i++)
{
n+=(*(p0+i)-'0')*pow(10,6-i);
}
return n;
}
void search(struct dianhua telbook[],int tel,int *n)
{
int i;
for (i=0;i<=*n-1;i++)
{
if ((telbook+i)->tel==tel)
{
(telbook+i)->totel++;
return;
}
}
(telbook+i)->tel=tel;
(telbook+i)->totel=1;
(*n)++;
}
int cmp( const void *a ,const void *b)
{
return (*(struct dianhua *)a).tel > (*(struct dianhua *)b).tel ? 1 : -1;
}
main()
{
int T,i,inttel,n=0; char tel[40]; struct dianhua *telbook;
scanf("%d",&T); getchar();
telbook=(struct dianhua *)malloc(T*sizeof(struct dianhua));
for (i=1;i<=T;i++)
{
gets(tel);
inttel=chuli(tel);
search(telbook,inttel,&n);
}
qsort(telbook,n,sizeof(*telbook),cmp);
for (i=0;i<=n-1;i++)
{
if ((telbook+i)->totel>1) printf("%03d-%04d %d\n",(telbook+i)->tel/10000,(telbook+i)->tel%10000,(telbook+i)->totel);
else printf("No duplicates.\n");
}
} 展开
#include<stdlib.h>
#include <math.h>
struct dianhua
{
int tel;
int totel;
};
char tihuan(char c)
{
if (c>='0'&&c<='9') return '1';
if ((c=='A')||(c=='B')||(c=='C')) return '2';
if ((c=='D')||(c=='E')||(c=='F')) return '3';
if ((c=='G')||(c=='H')||(c=='I')) return '4';
if ((c=='J')||(c=='K')||(c=='L')) return '5';
if ((c=='M')||(c=='N')||(c=='O')) return '6';
if ((c=='P')||(c=='R')||(c=='S')) return '7';
if ((c=='T')||(c=='U')||(c=='V')) return '8';
if ((c=='W')||(c=='X')||(c=='Y')) return '9';
return '0';
}
int chuli(char *p)
{
char c,*q,*p0=p;
int n=0,i;
while (*p!='\0')
{
c=tihuan(*p);
if(c=='1')
{
p++;
continue;
}
else if(c=='0')
{
q=p;
while(*q!='\0')
{
*q=*(q+1);
q++;
}
p--;
}
else
{
*p=c;
}
p++;
}
for (i=0;i<=6;i++)
{
n+=(*(p0+i)-'0')*pow(10,6-i);
}
return n;
}
void search(struct dianhua telbook[],int tel,int *n)
{
int i;
for (i=0;i<=*n-1;i++)
{
if ((telbook+i)->tel==tel)
{
(telbook+i)->totel++;
return;
}
}
(telbook+i)->tel=tel;
(telbook+i)->totel=1;
(*n)++;
}
int cmp( const void *a ,const void *b)
{
return (*(struct dianhua *)a).tel > (*(struct dianhua *)b).tel ? 1 : -1;
}
main()
{
int T,i,inttel,n=0; char tel[40]; struct dianhua *telbook;
scanf("%d",&T); getchar();
telbook=(struct dianhua *)malloc(T*sizeof(struct dianhua));
for (i=1;i<=T;i++)
{
gets(tel);
inttel=chuli(tel);
search(telbook,inttel,&n);
}
qsort(telbook,n,sizeof(*telbook),cmp);
for (i=0;i<=n-1;i++)
{
if ((telbook+i)->totel>1) printf("%03d-%04d %d\n",(telbook+i)->tel/10000,(telbook+i)->tel%10000,(telbook+i)->totel);
else printf("No duplicates.\n");
}
} 展开
2个回答
展开全部
大哥,你的程序写得又丑又长。 我贴一个5年前我写的程序,就是这道题目。请参考
#include <stdio.h>
#define M 10000000
int i,n,k,j,b[M];
char s[99],c;
int main(){
for(scanf("%d",&n);i++<n;){
scanf("%s",s);
for(k=j=0;s[j];){
c=s[j++];
if(c!=81&&c!=90&&c!=45)
k=k*10+(64<c?(c-(80<c)-59)/3:c-48);
}
b[k]++;
}
for(i=0;i<M;i++)if(1<b[i]){
n=i;
s[3]=45;
for(k=s[8]=j=0;j<7;j++){
s[6-j+(j<4)]=n%10+48;
n/=10;
}
printf("%s %d\n",s,b[i]);
}
if(k)printf("No duplicates.\n");
return 0;
}
微测检测5.10
2023-07-11 广告
2023-07-11 广告
信噪比测试是用来衡量音响器材的噪声抑制能力,通常采用以下步骤进行测试:1. 建立指定的输出参考电平并正确接好输入端,操作测量仪器,使这一电平成为0dB的基准值。2. 取消信号源,此时仪表指示的就是信噪比,但是表示成负值,比如,90dB的信噪...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询