| ||||||||||
| 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 | |||||||||
大家能帮忙看看吗?出现了TLE.我把思路写在下面./*思路:把输入的每一组电话号码改写成interger,由函数trsnb(转换成数字)
负责.然后把这一组数字中的最小者取出来.然后一个个对照这排数.如果相同的
话,把相同的数改成-1,同时修改相应的判断参数.这样判一组相同的数打一个.最后如果
都没打印过的话,就输出一个No duplicates.*/
#include <stdio.h>
#include <malloc.h>
int po(int a, int b){
int x,result=1;
for(x=0; x<b; x++){
result*=a;
}
return result;
}
int trsnb(char s[16], int od){
if (s[od]>='A' && s[od]<'Z'){
if (s[od]>='Q')
s[od]--;
return (s[od]-59)/3;
}
else if(s[od]>='0' && s[od]<='9'){
return (s[od]-48);
}
}
struct k{
char a[16];
}*ip;//input dials and (*)is often neglected
void main(){
int *st;//it is used to store transformed dials.
int n,i,ca,m,j,min,num;
scanf("%d",&ca);
ip=(struct k*)malloc(sizeof(struct k)*(ca+1));//apply for room
st=(int *)malloc(sizeof(int)*(ca+1));//warning st,ip begin with 1
for (n=1; n<=ca; n++){
scanf("%s",&(*(ip+n)).a);
*(st+n)=0;
j=1;//j for 1-7
for (i=0; (*(ip+n)).a[i]!='\0'; i++){
if ((*(ip+n)).a[i]!='-'){
*(st+n)+=trsnb((*(ip+n)).a,i)*po(10,(7-j));
j++;
}
}
}//all dials have been transformed to intergers.
int q=ca;
for (m=ca; m!=0;){
min=9999999;
num=0;//menbers of a group
for (n=1; n<=ca; n++){
if(*(st+n)!=0){
if(*(st+n)<min)
min=*(st+n);
}
}//find the min one of the group
for (n=1; n<=ca; n++){
if(*(st+n)==min){
*(st+n)=0;
num++;
m--;
}
}
if(num>1){
printf("%d-%d %d\n",min/10000,min%10000,num);
q--;
}
}
if(q==ca) printf("No duplicates.\n");
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator