团体程序设计天梯赛L1-027 出租
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
class MyCompare //创建谓词,从大到小排序
{
public:
bool operator()(int a, int b){
return a > b;
}
};
int main()
{
string phonenum;
cin >> phonenum;
set<int,MyCompare>s;
for(int i = 0; i < 11; i++) //将电话号码不重复,从大到小顺序存入set容器
s.insert(phonenum[i] - '0');
cout << "int[] arr = new int[]{"; //第一句的打印
for(set<int, MyCompare>::iterator it = s.begin(); it != s.end(); it++)
{
cout << *it;
if(++it != s.end())
cout << ",";
it--;
}
cout << "};" << endl;
cout << "int[] index = new int[]{";
for(int i = 0; i < 11; i++)
{
int j = 0;
for(set<int, MyCompare>::iterator it = s.begin(); it != s.end(); it++)
{
if((phonenum[i] - '0') == *it)
{
cout << j;
if(i+1 != 11)
cout << ",";
break;
}
j++;
}
}
cout << "};" << endl;
return 0;
}