Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41909 Accepted Submission(s): 12014
#include<queue> #include<map> #include<math.h> #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; #define N 100005 int num,cnt; char str[N]; char str2[N]; int a[N]; int main() { while(cin>>str2) { num=cnt=0; int k=0;int flag=1; memset(str,0,sizeof(str)); for(int i=0;str2[i];i++) { if(str2[i]==‘5‘&&flag)continue; str[k++]=str2[i];flag=0; } //cout<<str<<endl; for(int i=0;;i++) { if(str[i]==‘\0‘) { a[cnt++]=num; num=0; break; } if(str[i]==‘5‘) { if(str[i+1]==‘\0‘||str[i+1]==‘5‘)continue; a[cnt++]=num; num=0; continue; } num=num*10+(str[i]-48); } sort(a,a+cnt); int j; for(j=0;j<cnt-1;j++) printf("%d ",a[j]); printf("%d\n",a[j]); } return 0; }
#include<iostream> #include<sstream> #include<vector> #include<cstdlib> #include<algorithm> using namespace std; int main() { string str; while(cin>>str) { vector<string> v1; vector<int> v2; for(int i=0;i!=str.size();++i) { if(str[i]==‘5‘) str[i]=‘ ‘; } istringstream in(str); string temp; while(in>>temp) v1.push_back(temp); for(auto b=v1.cbegin();b!=v1.cend();++b) { int temp=atoi(b->c_str()); v2.push_back(temp); } sort(v2.begin(),v2.end()); auto b=v2.cbegin(); for(;b!=v2.cend()-1;++b) cout<<*b<<" "; cout<<*b<<endl; } return 0; }
原文:http://www.cnblogs.com/wmxl/p/4675066.html