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

求好心大神帮忙看看哪里错了?无限WA阿。C语言的。感谢万分

Posted by D_bing at 2012-03-28 20:27:39 on Problem 1002
#include<stdio.h>
#include<stdlib.h>
void input(long int s[],int n)
{
 int map[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
 char s1[100];
 int i,j;
 for(i=0;i<n;++i)
 {
  scanf("%s",s1);
  s[i]=0;
  for(j=0;j<100;++j)
  {
   if(s1[j]!='-')
   {
    if(s1[j]>='A'&&s1[j]<='Z')
     s[i]=s[i]*10+map[s1[j]-'A'];
    else if(s1[j]>='a'&&s1[j]<='z')
     s[i]=s[i]*10+map[s1[j]-'a'];
    else if(s1[j]>='0'&&s1[j]<='9')
     s[i]=s[i]*10+(s1[j]-'0');
   }
   if(s[i]>999999)
    break;
  }
 }
}
void output(long int s[],int n)
{
 int m=1,i,k,l=0;
 for(i=0;i<=n;++i)
 {
  k=0;
  if(s[i]==s[i+1])
   m=m+1;
  else
   k=1;
  if(m!=1&&k==1)
  {
   printf("%d%d%d-%d%d%d%d %d\n",s[i-1]/1000000,(s[i-1]%1000000)/100000,
    (s[i-1]%100000)/10000,(s[i-1]%10000)/1000,(s[i-1]%1000)/100,
    (s[i-1]%100)/10,s[i-1]%10,m);
   l=1;
   m=1;
  }
 }
 if(l==0)
  printf("No duplicates. \n");
}
int cmp(const void *a,const void *b)
{
 return *(int *)a - *(int *)b;
}
main()
{
 long int s[100001];
 int n;
 scanf("%d",&n);
 input(s,n);  //输入电话号码
 qsort(s,n,sizeof(s[0]),cmp);    //电话号码排序
 output(s,n);    //寻找重复并输出
 return 0;
}

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