将第一行中含有第二行中“23”的数输出并排序

来源:互联网 发布:罗马帝国扫矿软件 编辑:程序博客网 时间:2024/06/05 15:26

题目:输入一行数字123 423 5645 875 18623

输出 123 423 18623

 #include<iostream>#include<string>using std::string;using std::cin;using std::cout;using std::endl;using std::getline;#include<vector>using std::vector;#include <algorithm>string s; int main(){getline(cin,s);const char *const_p=(char *)malloc(sizeof(char)*s.length());const_p=s.c_str();char *p_str=(char *)malloc(sizeof(char)*s.length());strcpy(p_str,const_p);vector<string> strArry;vector<int> intArry;char *p=NULL;p=strtok(p_str," ");do{strArry.push_back(p);string s;s=strArry.back();if(s.find("23")==std::string::npos){strArry.pop_back();}else{intArry.push_back(atoi(p));}p=strtok(NULL," ");}while(p!=NULL); sort(intArry.begin(),intArry.end());for(int i=0;i<intArry.size();i++){cout<<intArry[i]<<" ";} system("pause");return 0;}


0 0
原创粉丝点击