国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1038. Recover the Smallest Number

2019-11-09 19:08:55
字體:
來源:轉載
供稿:網友

思想的話看這里吧。http://blog.csdn.net/sinat_29278271/article/details/48047877

比較巧妙。自己寫了好長的判斷也沒通過。

#include <iostream>#include <string>#include <algorithm>#include <vector>#include <stack>using namespace std;int N;vector <string> list;bool cmp(string s1, string s2) {	return s1 + s2 < s2 + s1;}int str2int(string s) {	int sum = 0;	for (int i = s.size() - 1; i >= 0; i--) {		sum *= 10;		sum += int(s[i] - '0');	}	return sum;}int main() {	cin >> N;	string s, small = "0";			for (int i = 0; i < N; i++) {		cin >> s;		if (str2int(s) == 0)//			cout << str2int(s) << endl;			continue;		list.push_back(s);	}	sort(list.begin(), list.end(), cmp);#ifdef _DEBUG	//for (int i = 0; i < list.size(); i++) {	//	cout << list[i] << endl;	//}#endif	bool tag = true;	bool tag2 = true;	for (int i = 0; i < list.size(); i++) {				if (i == 0) {			for (int j = 0; j < list[0].size(); j++) {				if (list[0][j] != '0') {//有非零					tag = false;				}						if (tag) {					continue;				}				else {					if (tag2) {						small.clear();						tag2 = false;					}					small.push_back(list[0][j]);				}			}		}		else {			small += list[i];		}	}	cout << small << endl;	return 0;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大渡口区| 绩溪县| 吉安县| 安泽县| 天门市| 子洲县| 资兴市| 甘南县| 阳新县| 博客| 毕节市| 灌南县| 宿松县| 鹰潭市| 益阳市| 城步| 元阳县| 云阳县| 胶南市| 沛县| 湟中县| 铁岭市| 巫山县| 西城区| 信丰县| 荃湾区| 涿州市| 阜阳市| 石城县| 余姚市| 广昌县| 天门市| 崇仁县| 灵璧县| 古交市| 静海县| 成武县| 丽江市| 报价| 汤原县| 精河县|