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

弱弱的问一下,这两个输入有什么不同?为什么一个ac了,一个wr了

Posted by luoxiaomao at 2006-11-05 18:14:26 on Problem 1002
一个为

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp(const void *p1,const void *p2)
{
    return *(int *)p1-*(int *)p2;   
}
int main()
{
    char g[100],ch[100];
    int n,i,j,k,h[100100],h1[30]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0},flag;
    scanf("%d",&n);
    for(i=0;i<n;i++) 
    {
         scanf("%s",g);k=0;
         for(j=0;j<strlen(g);j++)
         {
             if(g[j]>='0' && g[j]<='9') {ch[k]=g[j];k++;}
             if(g[j]>='A' && g[j]<'Z') {ch[k]=h1[(int)(g[j]-'A')]+'0';k++;}
         }
         ch[k]='\0';
         h[i]=atoi(ch);
    }
    qsort(h,n,sizeof(int),cmp);
    flag=1;
    for(i=0;i<n-1;)
    {
         j=i+1;while(h[i]==h[j] && j<n) j++;
         if(j-i>1) {flag=0;printf("%.3d-%.4d %d\n",h[i]/10000,h[i]%10000,j-i);}
         i=j;
    }
    if(flag) printf("No duplicates.\n");
    system("pause");
    return 0;
}

另一个为

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream.h>
int cmp(const void *p1,const void *p2)
{
    return *(int *)p1-*(int *)p2;   
}
int main()
{
    char g[100],ch[100];
    int n,i,j,k,h[100100],h1[30]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0},flag;
    scanf("%d",&n);
    cin.ignore();
    for(i=0;i<n;i++) 
    {
         gets(g);k=0;
         for(j=0;j<strlen(g);j++)
         {
             if(g[j]>='0' && g[j]<='9') {ch[k]=g[j];k++;}
             if(g[j]>='A' && g[j]<'Z') {ch[k]=h1[(int)(g[j]-'A')]+'0';k++;}
         }
         ch[k]='\0';
         h[i]=atoi(ch);
    }
    qsort(h,n,sizeof(int),cmp);
    flag=1;
    for(i=0;i<n-1;)
    {
         j=i+1;while(h[i]==h[j] && j<n) j++;
         if(j-i>1) {flag=0;printf("%.3d-%.4d %d\n",h[i]/10000,h[i]%10000,j-i);}
         i=j;
    }
    if(flag) printf("No duplicates.\n");
    system("pause");
    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