您的位置:首页 > 移动开发

SRM 583 Div II Level One:SwappingDigits

2013-06-23 16:44 549 查看
题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12609

#include <iostream>
#include <string>

using namespace std;

string minstr = "";

class SwappingDigits
{
public: string minNumber(string num);
};

string SwappingDigits::minNumber(string num)
{
string temp;
string mins = "";
for (int i = 0; i < num.size()-1; i++) {
for (int j = i+1; j < num.size(); j++) {
temp = num;
swap(temp[i], temp[j]);
if (temp[0] != '0' && mins == "") {
mins = temp;
} else {
if (temp[0] != '0' && temp < mins) {
mins = temp;
}
}
}
}

return mins;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: