本文主要是介绍ZTE 2018,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#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;
}
输入:一个长整型
输出:最小排列
这篇关于ZTE 2018的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!