ZTE 2018

来源:互联网 发布:浏览器注入js脚本 编辑:程序博客网 时间:2024/06/11 20:55


自己实在太垃圾了……

#include<iostream>#include<sstream>#include<vector>#include<cmath>#include<algorithm>using namespace std;int main(){long lockingkey,unlock=0;cin >> lockingkey;string str;stringstream stream;vector<int>vec;/*long先转换成string,再转换成char*/stream << lockingkey;stream >> str;const char* ch = str.c_str();const char* ch1 = ch + 1;/*字符串数组转换成整数数组*/if (*ch == '-') {while (*ch1 != '\0') {cout << *ch1 << endl;vec.push_back(*ch1 - '0');ch1++;}}else {while (*ch != '\0') {cout << *ch << endl;vec.push_back(*ch - '0');ch++;}}/*排序*/sort(vec.begin(), vec.end());vector<int>::iterator it = vec.begin();vector<int>::iterator it1 = it;int num = vec.size();int Num = 0;/*正数*/if (*ch != '-') {if (*it == 0) {for (; it1 != vec.end(); it1++) {if (*it1 != 0) break;}swap(*it, *it1);}for (; it != vec.end(); it++) {unlock += (*it)*pow(10, --num);}}/*负数*/else {for (; it != vec.end(); it++) {unlock += (*it)*pow(10, Num++);}unlock *= -1;}cout << unlock << endl;return 0;}

输入:一个长整型

输出:最小排列

原创粉丝点击