输入:
5
c d a bb e
输出:
a bb c d e
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int len;
cin>>len;
vector<string> str(len);
while(--len>=0){
cin>>str[len];
}
sort(str.begin(),str.end());
len=str.size()-1;
for(int i=0;i<=len;i++){
cout<<str[i]<<" ";
}
cout<<endl;
return 0;
}
输入:
a c bb
f dddd
nowcoder
输出:
a bb c
dddd f
nowcoder
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
string str;
vector<string> strs;
while(cin>>str){
strs.emplace_back(str);
if(cin.get()=='\n'){
sort(strs.begin(),strs.end());
int len=strs.size()-1;
for(int i=0;i<=len;i++){
cout<<strs[i]<<" ";
}
cout<<endl;
strs.clear();
}
}
return 0;
}
输入:
a,c,bb
f,dddd
nowcoder
输出:
a,bb,c
dddd,f
nowcoder
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>
using namespace std;
int main(){
string line;
while(getline(cin,line)){
istringstream sin(line);
string str;
vector<string> strs;
while(getline(sin,str,',')){
strs.emplace_back(str);
}
sort(strs.begin(),strs.end());
int len=strs.size()-1;
for(int i=0;i<len;i++){
cout<<strs[i]<<',';
}
cout<<strs[len]<<endl;
}
return 0;
}
class Solution {
public:
ListNode* insertionSortList(ListNode* head) {
if(!head||!head->next) return head;
ListNode* p,*q;//p指向要插入位置的前一个
//再标准头文件limits.h中
//#define INT_MAX 21474837
//#define INT_MIN (-INT_MAX - 1)
/*
C中int类型是32位的,范围是-21474838到21474837 。
(1)最轻微的上溢是INT_MAX + 1 :结果是 INT_MIN;
(2)最严重的上溢是INT_MAX + INT_MAX :结果是-2;
(3)最轻微的下溢是INT_MIN - 1:结果是是INT_MAX;
(4)最严重的下溢是INT_MIN + INT_MIN:结果是0 。
*/
ListNode* newhead=new ListNode(INT_MIN);
q=head->next;
newhead->next=head;
while(q){
for(p=newhead;p!=head;p=p->next){
if(q->val>=p->val&&q->val<=p->next->val) break;
}
if(p!=head){
head->next=q->next;
q->next=p->next;
p->next=q;
q=head->next;
}else{
head=head->next;
q=head->next;
}
}
return newhead->next;
}
};
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务