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

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

1038. Recover the Smallest Number

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

思想的話看這里吧。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;}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 思茅市| 锡林郭勒盟| 古丈县| 苗栗市| 教育| 海晏县| 望都县| 尚义县| 泸定县| 土默特右旗| 临沂市| 茌平县| 商城县| 上思县| 平顶山市| 珲春市| 五大连池市| 临邑县| 屏东市| 荣昌县| 崇信县| 南康市| 吉木乃县| 翁源县| 清水县| 新源县| 黄山市| 海盐县| 郑州市| 浦江县| 台东县| 海晏县| 崇文区| 呼图壁县| 黄平县| 阜阳市| 沾化县| 内黄县| 长武县| 石嘴山市| 怀远县|