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;
}
富港检测技术(东莞)有限公司_
2024-05-27 广告
2024-05-27 广告
ISTA3E程序是对相同产品的集合包装的综合模拟性能测试,集合包装件被定义为将一个产品、多个产品或包装件放置在滑板或托盘上,固定在一起或是作为一个单元运输。例如:一台机器由带瓦楞底托的托盘上、瓦楞侧围、顶盖包装,用缠绕膜缠绕在托盘上。用于评...
点击进入详情页
本回答由富港检测技术(东莞)有限公司_提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询