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 shakang at 2011-05-10 15:04:28 on Problem 1002
我们可以把字符串变成int型的整数来操作
具体操作方式如下:

         for(int i=0;i<t;i++)   //输入字符串 
                 scanf("%s",d[i]);
         for(int i=0;i<t;i++)     //字符串转换成int型整数 
          {       int k=6;
                 for(int j=0;d[i][j]!='\0';j++)
                         
                         switch(d[i][j])
                         {
                         case 'A':
                              case 'B':
                                   case 'C':s[i]+=2*pow(double(10),k--);break;
                         case 'D':
                              case 'E':
                                   case 'F':s[i]+=3*pow(double(10),k--);break;
                         case 'G':
                              case 'H':
                                   case 'I':s[i]+=4*pow(double(10),k--);break;
                         case 'J':
                              case 'K':
                                   case 'L':s[i]+=5*pow(double(10),k--);;break;
                         case 'M':
                              case 'N':
                                   case 'O':s[i]+=6*pow(double(10),k--);;break;
                         case 'P':
                              case 'R':
                                   case 'S':s[i]+=7*pow(double(10),k--);;break;
                         case 'T':
                              case 'U':
                                   case 'V':s[i]+=8*pow(double(10),k--);;break;
                         case 'W':
                              case 'X':
                                   case 'Y':s[i]+=9*pow(double(10),k--);;break;
                         case '-':break;
                         default :s[i]+=(d[i][j]-'0')*pow(double(10),k--);break;
                         }
                 }


下面就可以用排序来给这些int型的数据排序了;


不过最重要的一点:不要被“0000000”这种数据给欺骗了!
所以要用   %03d-%04d   这种输出方式(左对齐,不足3、4位以0补)

格式是:printf("%03d-%04d %d\n",s[i-1]/10000,s[i-1]%10000,sum);//sum是计数的

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