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 ...
随机推荐
- Hadoop MapReduce编程学习
一直在搞spark,也没时间弄hadoop,不过Hadoop基本的编程我觉得我还是要会吧,看到一篇不错的文章,不过应该应用于hadoop2.0以前,因为代码中有 conf.set("map ...
- SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转
694. Distinct Substrings Problem code: DISUBSTR Given a string, we need to find the total number o ...
- JAVA实例,求用户输入的整数是否是偶数
题目:用户能输入一个整数,输入后返回是偶数还是奇数. 偶数规则:除以2能整除的数称之为偶数,否则是奇数 实例: switch版 import java.util.Scanner; public cla ...
- 一款监控网络状态的好工具- Smokeping
最近工作中需要监测某个分公司到IDC机房的网络情况,到网络上找了不少软件,发现一款叫smokeping的开源软件还不错,它是rrdtool的作者制作的,在图形显示方面很漂亮,可以用来很好的检测网络状态 ...
- sphinx 全文搜索引擎安装与配置
sphinx 全文搜索引擎 sphinx的安装与配置 ------------------------------------------------------------------------- ...
- 中文系统下,UTF-8编码文本文件读取导致的错误
一.UTF-8编码文件读取导致的错误 有个txt文件,里面内容为: aaa bbb ccc 以UTF-8编码方式打开txt文件,顺序读取,将里面的值放到一个hashset中,并判断aaa是否在在has ...
- 利用python yielding创建协程将异步编程同步化
转自:http://www.jackyshen.com/2015/05/21/async-operations-in-form-of-sync-programming-with-python-yiel ...
- Centos 7配置LAMP
因为安装zabbix需要LAMP环境,特记录如下. LAMP指的Linux(操作系统).Apache HTTP 服务器,MySQL(有时也指MariaDB,数据库软件)和PHP(有时也是指Perl或P ...
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
游戏暂停界面: cocos2d-x中游戏暂停界面提供的思路是用pushScene()和popScne(),即推进和弹出场景,当游戏暂停时,推进(pushScene())暂停场景,之前运行的场景将会自动 ...
- ProGuard
ProGuard的作用: 1.创建紧凑的代码文档是为了更快的网络传输,快速装载和更小的内存占用. 2.创建的程序和程序库很难使用反向工程. 3.所以它能删除来自源文件中的没有调用的代码 4.充分利用 ...