Northwestern Polytechnical University Summer Camp 2018 The second question

Subject has no description of the number of each set of input data, so only one line all the input, and then separated according to space regions.

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
	
	int n;
	cin>>n;
	getchar();
	for(int i = 0;i < n;i++){
		string s;
		vector<int>v;
		getline(cin,s);
		cout<<s<<endl;
		int index = s.find_first_of(' ');
		while(index != -1){
			index = s.find_first_of(' ');
			int num = atoi(s.substr(0,index).c_str());
			v.push_back(num);
			s = s.substr(index+1,s.length()-index);
		}
		sort(v.begin(),v.end());
		for(int j = 0;j < v.size();j++){
			if(j == 0){
				printf("%d",v[j]);
			}else{
				printf(" %d",v[j]);
			}
		}
		printf("\n");
	}
	return 0;
}

 

Published 313 original articles · won praise 64 · views 90000 +

Guess you like

Origin blog.csdn.net/PriestessofBirth/article/details/104922018