| ||||||||||
| 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 | |||||||||
求助:各位高手请帮忙看看吧,本机上短数据没问题,一提交就不行了#include <stdlib.h>
#include <string.h>
#include <stdio.h>
struct lnode /*每个号码存入一字符数组*/
{
char a[8];
};
void encode(char *x,char y[8]) /*对每个号码编码*/
{
int i,j;
for(i=j=0;x[i]!='\0'&&j<7;i++)
{
if(x[i]<'Q'&&x[i]>='A')
y[j]=(x[i]-'A')/3+2+'0',j++;
else if(x[i]>'Q'&&x[i]<'Z')
y[j]=9-('Y'-x[i])/3+'0',j++;
else if(x[i]<='9'&&x[i]>='0')
y[j]=x[i],j++;
}
y[7]='\0'; /*字符串结束*/
}
main()
{
int j,l;
long i,k,n;
char *s,t[7];
struct lnode *nodes;
scanf("%ld",&n);
nodes=(struct lnode *)calloc(n+1,sizeof(struct lnode)); /*动态分配n+1个结构体*/
getchar();
for(i=0;i<n;i++)
{
gets(s); /*读入每个号码*/
encode(s,nodes[i].a);
}
for(i=0;i<n;i++) /*从小到大排序*/
for(j=i;j<n;j++)
{
if(strcmp(nodes[i].a,nodes[j].a)>0)
strcpy(t,nodes[i].a),strcpy(nodes[i].a,nodes[j].a),strcpy(nodes[j].a,t);
}
nodes[n].a[0]='\0'; /*最后一个赋0*/
for(k=1,l=i=0;i<n;i++)
{
if(strcmp(nodes[i].a,nodes[i+1].a)==0)
k++;
else if(k>1)
{
l++;
for(j=0;j<7;j++) /*有相同时输出*/
{
if(j==3)
printf("-");
printf("%c",nodes[i].a[j]);
}
printf(" %ld\n",k);
k=1;
}
}
if(l==0) /*无相同输出*/
printf("No duplicates.");
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator