Topcoder SRM 583 DIV2 SwappingDigits

题目题意是交换一次,使数字最小,且数字前面不能有前导0

    string minNumber(string num)
    {
        string res = num;
        for(int i = 0 ; i < num.size(); i ++ ){
            for(int j = i + 1;  j < num.size(); j ++  ){
                    if(i == 0 && num[j] == '0') continue;
                    else{
                        swap(num[i],num[j]);
                        res = res > num ? num : res;
                        swap(num[i],num[j]);
                    }
            }
        }
        return res;
    }

  

posted @ 2013-06-19 09:05  OpenSoucre  阅读(334)  评论(0编辑  收藏  举报