NYOJ 905 卡片游戏
卡片游戏
- 描写叙述
- 小明近期宅在家里无聊。于是他发明了一种有趣的游戏。游戏道具是N张叠在一起的卡片,每张卡片上都有一个数字,数字的范围是0~9,游戏规则例如以下:
首先取最上方的卡片放到桌子上。然后每次取最上方的卡片,放到桌子上已有卡片序列的最右边或者最左边。当N张卡片所有都放到桌子上后。桌子上的N张卡片构成了一个数。这个数不能有前导0,也就是说最左边的卡片上的数字不能是0。游戏的目标是使这个数最小。
如今你的任务是帮小明写段程序,求出这个最小数。
- 输入
- 第一行是一个数T,表示有T组測试数据。
然后以下有T行, 每行是一个仅仅含有0~9的字符串,表示N张叠在一起的卡片。最左边的数字表示最上方的卡片。
[Technical Specification]
T<=1000
1 <= N <= 100 - 输出
- 对于每组測试数据,请在一行内输出能得到的最小数。
- 例子输入
-
3
565
9876543210
9876105432 - 例子输出
-
556
1234567890
1678905432AC码:
#include<stdio.h>
int main()
{
char str[105],ch[110],s;
int T,i,j,left,right;
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
s='9';
for(i=0;str[i]!='\0';i++)
{
if((str[i]!='0')&&str[i]<=s)
{
s=str[i];
j=i;
}
}
left=53;
right=52;
ch[left]='9';
for(i=0;str[i]!='\0';i++)
{
if(i>=j)
break;
if(str[i]<=ch[left])
{
left--;
ch[left]=str[i];
}
else
{
right++;
ch[right]=str[i];
}
}
printf("%c",s);
for(i=left;i<=right;i++)
printf("%c",ch[i]);
for(i=j+1;str[i]!='\0';i++)
printf("%c",str[i]);
printf("\n");
}
return 0;
}
NYOJ 905 卡片游戏的更多相关文章
- 【sicily】卡片游戏
卡片游戏 Time Limit: 1sec Memory Limit:32MB Description 桌上有一叠牌,从第一张牌(即位于顶面的牌)开始从上往下依次编号为1~n.当至少还剩两张牌 ...
- Sicily 1931. 卡片游戏
题目地址:1931. 卡片游戏 思路: 纯属数据结构中队列的应用,可以练练手. 具体代码如下: #include <iostream> #include <queue> usi ...
- 卡片游戏(hdu4550)贪心
卡片游戏 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
- nyoj905 卡片游戏
卡片游戏 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 小明最近宅在家里无聊,于是他发明了一种有趣的游戏,游戏道具是N张叠在一起的卡片,每张卡片上都有一个数字,数字 ...
- Java实现 LeetCode 822 翻转卡片游戏(暴力)
822. 翻转卡片游戏 在桌子上有 N 张卡片,每张卡片的正面和背面都写着一个正数(正面与背面上的数有可能不一样). 我们可以先翻转任意张卡片,然后选择其中一张卡片. 如果选中的那张卡片背面的数字 X ...
- hdu 4550 卡片游戏 贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4550 题意:有n(n <= 100)个0~9之间的卡片,从左往右将卡片放到之前的卡片最左边或者最 ...
- [Swift]LeetCode822. 翻转卡片游戏 | Card Flipping Game
On a table are N cards, with a positive integer printed on the front and back of each card (possibly ...
- [LeetCode] Card Flipping Game 翻卡片游戏
On a table are N cards, with a positive integer printed on the front and back of each card (possibly ...
- 【XSY1591】卡片游戏 DP
题目描述 有标有数字为\(1\)~\(9\)的卡片各\(a_1,a_2\cdots a_9\)张,还有标有乘号的卡片\(m\)张.从中取出\(n\)张按任意顺序排列,取出两个乘号相邻和乘法在边界上的非 ...
随机推荐
- uva 10828 高斯消元求数学期望
Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name ...
- c++函数学习-关于c++函数的林林总总
本文是我在学习c++过程中的一些思考和总结,主要是c++中关于函数的林林总总.欢迎大家批评和指正,共同学习. os version: ubuntu 12.04 LTS gcc version: gcc ...
- POJ 2411Mondriaan's Dream
题目: Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after prod ...
- ajax 分页(jquery分页插件pagination) 小例2
封装成:myPagination.js// ajax分页 function sendAjax(flag, dataParam, url, callback) {//封装的ajax: var shus ...
- TStringList的Find,IndexOf和Sort
procedure TForm1.Button1Click(Sender: TObject); var MyList: TStringList; begin MyList := TStringList ...
- hdu 1254(搜索题)
推箱子 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- Lucene.net站内搜索-最简单搜索引擎代码
Lucene.Net核心类简介 先运行写好的索引的代码,再向下讲解各个类的作用,不用背代码. (*)Directory表示索引文件(Lucene.net用来保存用户扔过来的数据的地方)保存的地方,是抽 ...
- android 什么时候call super.onDestory()等
Methods you override that are part of component creation (onCreate(), onStart(), onResume(), etc.), ...
- 【APIO2015】Palembang Bridges
题目描述 一条东西走向的穆西河将巴邻旁市一分为二,分割成了区域 $A$ 和区域 $B$. 每一块区域沿着河岸都建了恰好 $1000000001$ 栋的建筑,每条岸边的建筑都从 $0$ 编号到 $100 ...
- remove xcode recent projects from dock menu 移除xcode dock菜单显示的项目列表
Launch Xcode Select File->Open Recent->Clear Menu Right-click the Xcode icon and select Show A ...