问题 S: 近似排序
时间限制: 1.000 Sec 内存限制: 128 MB
提交 状态
题目描述
读入正整数x和y,将这两个数之间(包括这两个数本身)的所有数按下述特别规则排序后输出。
该特别规则是:按两数倒过来的值进行比较决定其大小,如30倒过来为3,29倒过来为92,则29大于30
输入
一行两个整数x和y,用一个空格隔开,1<=x<=y<=1000000000,y-x<=100
输出
包括y-x+1行,每行一个正整数,按两数倒过来的值进行比较决定其大小,然后由小到大输出
样例输入 Copy
22 39
样例输出 Copy
30 31 22 32 23 33 24 34 25 35 26 36 27 37 28 38 29 39
# include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
set<pair<ll,ll>> pp;
int main(){
ll a,b,c;
cin>>a>>b;
for(ll t=a;t<=b;t++){
s=to_string(t);//c++11的函数:将整形变为字符串
reverse(s.begin(),s.end());//题中要求翻转比较
ll x=stoi(s);//c++11的函数:将字符串变为整形
pp.insert(pair<ll ,ll>(x,t));//插入这两对数字
} //pair默认对first升序,当first相同时对second升序;
//所以我们此时就把这个x就弄成first
set<pair<ll,ll>> ::iterator it;
for(it=pp.begin();it!=pp.end();it++){
cout<<it->second<<"\n";//输出second呗,因为first是我们翻转后的,second是原来的
}
}