1038. Recover the Smallest Number (30)

    xiaoxiao2021-03-26  21

    注意除去前面零的几种情况

    #include<iostream> #include<algorithm> #include<vector> #include<map> #include<string> #include<set> using namespace std; vector<string> s; bool comp(string a, string b){ string s1 = a + b; string s2 = b + a; if(s1 < s2) return true; else return false; } int main(){ int n; cin>>n; for(int i = 0; i < n; i++){ string temp; cin>>temp; s.push_back(temp); } sort(s.begin(),s.end(),comp); bool beginzero = true; for(int i = 0; i < n; i++){ int j = 0; while(j < s[i].size()){ if(s[i][j] != '0' || beginzero == false){ printf("%c",s[i][j]); beginzero = false; } j++; } } if(beginzero == true) cout<<0;//都是零 return 0; }

    1、样例的情况,只要考虑首串前面部分元素的零问题

    2、可能存在一个串或多个串元素都是零

    3、所有串所有元素都是零,输出结果应为“0”,序号2的两分点就是考查这个

    转载请注明原文地址: https://ju.6miu.com/read-660642.html

    最新回复(0)