蓝色xx邮 蓝色xx邮
关注数: 19 粉丝数: 20 发帖数: 310 关注贴吧数: 2
一道偶数排序的题 给定n个正整数,对其中的偶数按递增次序排序。 输入 第一行是一个正整数:测试用例数目,最多为5。之后,每个测试用例包括两行: l        第1行给出整数数目n,1≤n≤100000,每个整数范围为 [0,100000) l        第2行给出n个整数 输出 对于每个测试用例: l        输出“Case #:”,#表示序号 l        输出偶数排序后的n个整数 样例输入 2 3 4 2 1 3 3 2 1 样例输出 Case 1: 2 4 1 Case 2: 3 2 1 下面是我的代码: #include<stdio.h> int main() {      int ncount,count=1;      int n,i,j;      int temp,index;      int a[100000];      scanf("%d",&ncount);      while(ncount--)      {          scanf("%d",&n);          for(i=0;i<n;++i)              scanf("%d",a+i);          for(i=0;i<n;++i)              if(a[i]%2==0)                 break;          for(;i<n-1;i++)          {              index=i;              for(j=i+1;j<n;j++)                  if(a[j]%2==0&&a[j]<a[index])                      index=j;              if(index!=i)              {                  temp=a[i];                  a[i]=a[index];                  a[index]=temp;              }          }          printf("Case %d:\n",count++);          for(i=0;i<n;++i)              i==0?printf("%d",a[i]):printf(" %d",a[i]);          printf("\n");      } } 代码运行超时,求更高效的代码。。。。 请说一下思路,或者使用的数据结构。。。
求助,下面代码为什么在vc6里有warning #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int main() {      vector<string> words;      string temp;      while(cin>>temp)          words.push_back(temp);      cout<<"Number of words:"<<words.size()<<endl;      sort(words.begin(),words.end());      for(int i=0;i<words.size();++i)          if(i==0||words[i-1]!=words[i])              cout<<words[i]<<"\n\n";          return 0; }--------------------Configuration: play_02_23 - Win32 Debug-------------------- Compiling... play_01.cpp warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char ,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std:: char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information c:\program files\microsoft visual studio\vc98\include\vector(39) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information c:\program files\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information Linking... play_02_23.exe - 0 error(s), 4 warning(s)
1 下一页