PAT1038. Recover the Smallest Number
//意识到一个重要错误,一直以为atoi,itoa是windows独有的,linux下不可用,直到刚刚。。。
//string+=比strcat好用多了,字符比较也方便的多,但是用scanf读入string,好麻烦。。。cin读入老是出错不晓得为什么,cin对于空格和换行符的处理还不是很清楚,c++没有系统学习,半c半++中。。。。,刷完一定找机会吧c++系统一下
//突然想起来第一次刷时,居然一个一个字符的比较。。。。。哭晕
//该方法来自晴神宝典
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef struct
{
char str[10];
}node;
vector<node>list;
bool cmp(node a,node b)
{
char s1[20],s2[20];
strcpy(s1,a.str);strcpy(s2,b.str);
strcat(s1,b.str);strcat(s2,a.str);
return strcmp(s1,s2)<0;
}
int main()
{
freopen("input.txt","r",stdin);
int i,n;
long int s;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
node tmp;
scanf("%s",tmp.str);
s=atoi(tmp.str);
if(s!=0)list.push_back(tmp);
}
if(list.size()==0)printf("0");
else
{
sort(list.begin(),list.end(),cmp);
s=atoi(list[0].str);
printf("%ld",s);
for(i=1;i<list.size();i++)printf("%s",list[i].str);
}
printf("\n");
}
return 0;
}
PAT1038. Recover the Smallest Number的更多相关文章
- pat1038. Recover the Smallest Number (30)
1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...
- 把数组排成最小的数/1038. Recover the Smallest Number
题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. Give ...
- 1038. Recover the Smallest Number (30) - 字符串排序
题目例如以下: Given a collection of number segments, you are supposed to recover the smallest number from ...
- A1038. Recover the Smallest Number
Given a collection of number segments, you are supposed to recover the smallest number from them. Fo ...
- PAT甲1038 Recover the smallest number
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1038 Recover the Smallest Number (30 分)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- 1038. Recover the Smallest Number (30)
题目链接:http://www.patest.cn/contests/pat-a-practise/1038 题目: 1038. Recover the Smallest Number (30) 时间 ...
- PAT 1038 Recover the Smallest Number[dp][难]
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to r ...
- PAT 甲级 1038 Recover the Smallest Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 Given a collection of ...
随机推荐
- 一次非常有意思的 SQL 优化经历
我用的数据库是mysql5.6,下面简单的介绍下场景 课程表 create table Course( c_id int PRIMARY KEY, name varchar(10) ) 数据100条 ...
- AP_AP系列 - 供应商管理(案例)
2014-07-03 Created By BaoXinjian
- DBA_FND Load程式迁移工具介绍和应用(案例)
2014-06-10 Created By BaoXinjian
- [物理学与PDEs]书中的错误指出
记号意义: P--Page, 第几页; L--Line, 顺数第几行; LL--Last Line, 倒数第几行. P 64 L 1 ``15)'' should be ``14)''. P 70 L ...
- jquery实现的下拉和收缩代码实例
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta ...
- DevExpress打印功能 z
一.打印功能说明: 打印功能,我们有多种实现方式,可以根据需要自行选择,我简单的总结下两种方法. (1).使用微软.net框架自带的PrintDocument,这种方式是直接借助Graphics,自行 ...
- 学习vim命令:“:w !sudo tee %”
学习vim命令:“:w !sudo tee %” Original URL:http://www.haw-haw.org/node/1501 原文来自于commandlinefu 原文是这样解释这个命 ...
- C语言 段位
C语言允许在一个结构体中以位为单位来指定其成员所占内存长度,这种以位为单位的成员称为"位段"或"位域" 在结构体中位段的定义格式为: unsignede < ...
- C# 数据回滚
public int GetExecteQuery(string strAddSql, string strUpdateSql, string strDelSql) { SqlConnection c ...
- cocos2d-x 在xcode IOS模拟器中 开启IOS多点触控
在初始化代码中,开启当前层接受触摸 this->setTouchEnabled(true); 在AppController.mm文件中,设置开启多点触控 在- (BOOL)application ...