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

现在才完全明白Runtime Error与Time Limit Exceed是有区别的,我用最原始的方法过了……

Posted by zrjufo at 2006-07-21 00:28:04 on Problem 1007
有兴趣就比较一下吧:
以下的程序是我通过了的:
#include<iostream>
#include<string>
using namespace std;
struct DNA{
       string str;
       int length;       
};
int count(string str,int len){
     int  count=0;
     for(int i=0;i<len;i++)
     for(int j=i+1;j<len;j++)
     {
           if(str[i]>str[j])
           count++;
           else continue;  
     }
     return count;
}
bool sort(DNA str[],int len,int num){
     DNA tmp;
     for(int i=0;i<num;i++)
     for(int j=i+1;j<num;j++){
           if(str[i].length>str[j].length)
           {
               tmp=str[i];
               str[i]=str[j];
               str[j]=tmp;
           }
     }   
     return 1;
}     
int main(){
    DNA DNA_str[200];
    int len,num;int i;
    cin>>len>>num;
    for(i=0;i<num;i++){
                       cin>>DNA_str[i].str;
                       DNA_str[i].length=count(DNA_str[i].str,len);
                       }
    sort(DNA_str,len,num);
    for(i=0;i<num;i++){
    cout<<DNA_str[i].str<<endl;
    }
  //  system("pause");
    return 1;
                       
}                                    
以下的程序是Time Limit Exceed的:
#include<iostream>
#include<string>
using namespace std;
long count(string str,int len){
     long count=0;
     for(int i=0;i<len;i++)
     for(int j=i+1;j<len;j++)
     {
           if(str[i]>str[j])
           count++;
           else continue;  
             
     }
     return count;
}
bool sort(string str[],int len,int num){
     string tmp;
     for(int i=0;i<num;i++)//&Oacute;&Atilde;&Atilde;°&Aring;&Yacute;&Euml;&atilde;·¨
     for(int j=i+1;j<num;j++){
           if(count(str[i],len)>count(str[j],len))
           {
               tmp=str[i];
               str[i]=str[j];
               str[j]=tmp;
           }
     }   
     return 1;


}     
int main(){
    int len,num;
    string str[100];
    for(int i=0;i<100;i++)
    str[i]="";
    cin>>len>>num;
    for(int i=0;i<num;i++){
            cin>>str[i];
            }
    sort(str,len,num);
    for(int i=0;i<num;i++)
    cout<<str[i]<<endl;
    
    
   // system("pause");
}
本质是一样的。但实际就是不一样.

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