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

Re:谢谢大家,终于过了,有几点经验和原代码:

Posted by pladene at 2003-07-10 19:25:56 on Problem 1002
In Reply To:谢谢大家,终于过了,有几点经验和原代码: Posted by:yuenyun at 2003-07-10 19:20:16
> 一:C比C++高魈!
> 二:调用的STL快排看起来不好,但比自己写的快排要好的多!
> 三:有些东西并不是算法错,而是你工具选的好不好
> 4:谢谢大家,谢谢谢谢,老宋,你太牛了!
> 
> 
> Source
> 
> Problem Id:1002  User Id:yuenyun 
> Memory:440K  Time:781MS
> Language:C++  Result:Accepted
> 
> Source 
> //调用C的输入输出,但用库函数的快排 
> #include <iostream> 
> #include <stdlib.h> 
> //#include <search.h> 
> using namespace std; 
>     int a[100000]; 
>     char b[40]; 
> 
> 
> int cmp(const void *t1,const void *t2)                                      
>  {int *a,*b;  
>   a=(int *)t1; b=(int *)t2;  
>   if (*a>*b) return 1;  
>   if (*a<*b) return -1;  
>   return 0;  
>  }  
> 
> void main() 
> { 
> 
>     int num; 
> //    cin>>num; 
>     scanf("%d",&num); 
>     if (num<2) 
>    { 
> //        cin>>b; 
>         scanf("%s",b); 
> //        cout<<"No duplicates."; 
>         printf("No duplicates."); 
>     } 
>     else  
>     { 
>     for (int i=0;i<num;i++) 
>     { 
> //        cin>>b; 
>         scanf("%s",b); 
>         int result=0; 
>         for (int j=0;j<strlen(b);j++) 
>         { 
>                 switch(b[j]) 
>                 { 
>                 case('A'): 
>                 case('B'): 
>                 case('C'): 
>                     { 
>                         b[j]='2'; 
>                         break; 
>                     } 
>                 case('D'): 
>                 case('E'): 
>                 case('F'): 
>                     { 
>                         b[j]='3'; 
>                         break; 
>                     } 
>                 case('G'): 
>                 case('H'): 
>                 case('I'): 
>                     { 
>                         b[j]='4'; 
>                         break; 
>                     } 
>                 case('J'): 
>                 case('K'): 
>                 case('L'): 
>                     { 
>                         b[j]='5'; 
>                         break; 
>                     } 
>                 case('M'): 
>                 case('N'): 
>                 case('O'): 
>                     { 
>                         b[j]='6'; 
>                         break; 
>                     } 
>                 case('P'): 
>                 case('R'): 
>                 case('S'): 
>                     { 
>                         b[j]='7'; 
>                         break; 
>                     } 
>                 case('T'): 
>                 case('U'): 
>                 case('V'): 
>                     { 
>                         b[j]='8'; 
>                         break; 
>                     } 
>                 case('W'): 
>                 case('X'): 
>                 case('Y'): 
>                     { 
>                         b[j]='9'; 
>                         break; 
>                     } 
> 
>              
>                 } 
>      
> 
>                   if (b[j]>='0'  &&  b[j]<='9') 
>                   { 
>                       result=10*result+b[j]-('1'-1); 
>                   } 
>         } 
>         a[i]=result; 
>     } 
>   qsort(a,num,sizeof(int),cmp); 
> 
>   int flag=0;                //是否是不存在有重复的串 
>   int pp=0; 
>     while(pp<num)            //记数指针pp遍历num一遍而已,不算多吧 
>     { 
>         int sum=1; 
>         int i=1; 
>         while(a[pp]==a[pp+i])   //只是记录重复的串个数,其并不重复记,因为它往后移动时,PP会动所以 
>                                 //其外部循环并没有累计记数,即它和外部大循环在一起才记了NUM次; 
>         { 
>             i++; 
>             sum++; 
>         } 
>         if (sum>1)              //如果记数值大于1那么就输出; 
>         { 
>             int x1=a[pp]/10000;          //前3位 
>             int y1=a[pp] % 10000;         //后4位 
>      
>             if (x1>99)                   //如果前三位不足,看其有几位之前用0补足3位;    
> //                     cout<<x1<<"-"; 
>                     printf("%d-",x1); 
> 
>             else if (x1>9) 
> //                    cout<<"0"<<x1<<"-"; 
>                     printf("0%d-",x1); 
> //                    printf("%d",x1); 
> //                    printf("-"); 
>             else  
> //                cout<<"00"<<x1<<"-"; 
>                     printf("00%d-",x1); 
> //                    printf("%d-",x1); 
>             if (y1>999)                    //如果后4位不足,看其有几位用0补足4位; 
> //                cout<<y1<<" "<<sum<<endl; 
>                 printf("%d %d\n",y1,sum); 
>             else if (y1>99) 
> //                cout<<"0"<<y1<<" "<<sum<<endl; 
>                 printf("0%d %d\n",y1,sum); 
>             else if (y1>9) 
> //                cout<<"00"<<y1<<" "<<sum<<endl; 
>                 printf("00%d %d\n",y1,sum); 
>             else if (y1>=0) 
> //                cout<<"000"<<y1<<" "<<sum<<endl; 
>                 printf("000%d %d\n",y1,sum); 
>                 flag=1;                    //只要有一组多于2个的串就将标志FLAG为1; 
> 
>             } 
>          
>         pp=pp+i; 
>     } 
> if (flag==0)                          //整个大循环完了后,看FLAG如为0则输出。。。   
> //  cout<<"No duplicates."; 
>     printf("No duplicates."); 
>     } 
> } 

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