PAT A1038 Recover the Smallest Number 算法问题和关于'0'和0的小错误
2015-03-07 11:09
246 查看
//ac,改了一次,s[0]!='0',我写成了s[0]!=0 //注意连接起来最小才是最小 //+表示字符串的连接 //注意去除前导0总是要考虑字符串长度为0,A1060也是这样的 #include<string> #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int maxn=10010; string str[maxn];//注意这里string 应该是不定长的 using namespace std; bool cmp(string a,string b){ return a+b<b+a;//这里加号表示连接符 } int main(){ int n; cin>>n; for(int i=0;i<n;i++){ cin>>str[i]; } sort(str,str+n,cmp); //结果最好弄一个新的字符串,方便统一操作,A1060那题也是这样的 string ans; for(int i=0;i<n;i++){ ans+=str[i]; } //重点,去掉前导0 while(ans.size()!=0&&ans[0]=='0'){//去掉前导0的时候始终注意字符串长度不为0 ans.erase(ans.begin());//注意是ans.begin()而不是直接的0 } if(ans.size()==0) cout<<0;//注意字符串长度为0的处理 else cout<<ans; return 0; }
相关文章推荐
- PAT A1038 recover the smallest number (30)
- 1038. Recover the Smallest Number
- 关于Android4.0 emulator-arm.exe-应用程序错误,内存不能为"read"问题解决方法
- Recover the Smallest Number (30)
- 1038—Recover the Smallest Number (30)
- 关于LinerrLayout问题,总是出现"LinearLayout" must be followed by the ' = ' character.
- 浙大PAT_1038:Recover the Smallest Number 解题报告
- [转]关于 "the serializable class XXX does not declare a static final seriaVersionUID..."的问题 (2012-03-1
- PAT (Advanced Level) Practise 1038 Recover the Smallest Number (30)
- 关于ubuntu无法开机问题,显示安装错误 ubuntu install problem the configuration defaults for gnome power manager have
- PAT (Advanced Level) Practise 1038 Recover the Smallest Number (30)
- 问题版本关于运行错误:java.lang.UnsupportedClassVersionError: Bad version number in .class file
- 1038. Recover the Smallest Number
- 【PAT1038】Recover the Smallest Number 字符串组合大小
- 1038. Recover the Smallest Number
- 关于The entity name must immediately follow the '&' in the entity reference错误的问题
- [排序]PAT1038 Recover the Smallest Number
- PAT_1038: Recover the Smallest Number
- pat 1038 Recover the Smallest Number
- 1038. Recover the Smallest Number