Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

奇怪的数据!!

Posted by 20082501gong at 2010-07-23 16:21:21 on Problem 1002
这道题太奇怪了  
12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
上面给的测试数据我直接粘贴上去的话一瞬间就出答案了,但是我在离线OJ上测试这组数据居然要7,8s,当然提交的时候也超时了,太奇怪了,不知道是哪有问题??大家帮一下忙

代码:
[code=C/C++][/code]
  #include <stdio.h>
#include <string.h>
#include <stdlib.h>

void fun1();
void fun2();

char a[100];
int cout=0;
int cout2=0;
int flag = 0;

struct ss  
{
int nuber;
char b[9];
int p;
int value;
};
struct ss c[100000];

int cmp1 ( const void *e , const void *f )   
  {   
return (*(ss *)e).nuber - (*(ss *)f).nuber ;
  }   


int main()
{
int n; 
int i=0;
char ch;
// while (scanf("%d",&n)!=EOF)
// {
scanf("%d",&n);
ch = getchar();
  
while (n--)
{
scanf("%s",a);
// gets(a);
fun1();//处理字符串
fun2(); // 
}
qsort(c,cout2,sizeof(struct ss),cmp1);
for (i=0;i<cout2;i++)
{
if (c[i].value != 1)
{
printf("%s %d\n",c[i].b,c[i].value);
flag = 1;
}
}
if (flag == 0)
{
printf("No duplicates.\n");
}
// } 
return 0;
}

void fun1()
{
int i;
c[cout].nuber = 0;  
c[cout].p = 0;
c[cout].value = 1;
for (i=0;a[i];i++)
{
if (a[i]>='0'&&a[i]<='9')
{
c[cout].b[c[cout].p++] = a[i];
c[cout].nuber = c[cout].nuber*10+a[i]-'0';
}
else if (a[i]>='A'&&a[i]<='C')
{
c[cout].b[c[cout].p++] = '2';
c[cout].nuber = c[cout].nuber*10+2;
}
else if (a[i]>='D'&&a[i]<='F')
{
c[cout].b[c[cout].p++] = '3';
c[cout].nuber = c[cout].nuber*10+3;
}
else if (a[i]>='G'&&a[i]<='I')
{
c[cout].b[c[cout].p++] = '4';
c[cout].nuber = c[cout].nuber*10+4;
}
else if (a[i]>='J'&&a[i]<='L')
{
c[cout].b[c[cout].p++] = '5';
c[cout].nuber = c[cout].nuber*10+5;
}
else if (a[i]>='M'&&a[i]<='O')
{
c[cout].b[c[cout].p++] = '6';
c[cout].nuber = c[cout].nuber*10+6;
}
else if (a[i]=='P'||a[i]=='R'||a[i]=='S')
{
c[cout].b[c[cout].p++] = '7';
c[cout].nuber = c[cout].nuber*10+7;
}
else if (a[i]>='T'&&a[i]<='V')
{
c[cout].b[c[cout].p++] = '8';
c[cout].nuber = c[cout].nuber*10+8;
}
else if (a[i]>='W'&&a[i]<='Y')
{
c[cout].b[c[cout].p++] = '9';
c[cout].nuber = c[cout].nuber*10+9;
}

if (c[cout].p==3)
{
c[cout].b[c[cout].p++] = '-';
}
}
c[cout].b[8] = '\0';
cout++;
cout2++;
}
void fun2()
{
int i;
int key = cout2 -1;
for (i=0;i<cout2-1;i++)
{
if (c[key].nuber == c[i].nuber)
{
c[i].value ++; 
cout2--;
cout--;
return ;
}
} 
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator