hdu 4550
c:
#include<stdio.h>
#include<string.h>
#define N 300
int f[N];
char s[N];
int main() {
int t,m,i,front,tear,j;
char min;
scanf("%d",&t);
while(t--) {
scanf("%s",s);
memset(f,0,sizeof(f));
m=strlen(s);
front=tear=m;
f[front]=s[0]-'0';
min='9';
for(i=0;s[i];i++)
if(min>=s[i]&&s[i]!='0') {
min=s[i];
j=i;
}
for(i=1;s[i];i++) {
if(i==j)
f[--tear]=s[i]-'0';
else
if(i>j)
f[++front]=s[i]-'0';
else
if(i<j) {
if(s[i]-'0'>f[tear])
f[++front]=s[i]-'0';
else
f[--tear]=s[i]-'0';
}
}
for(i=tear;i<=front;i++)
printf("%d",f[i]);
printf("\n");
}
return 0;
}
c++
#include<cstring>
#include<iostream>
#include<string>
using namespace std;
#define N 1010
char s[N];
int main(){
int T,i;
char m='9';
string a;
scanf("%d",&T);
while(T--){
scanf("%s",s);
a=s[0];
int j=0;
for(i=0;s[i];i++){
if(s[i]!='0'){//找到非0最小的数
if(m>=s[i])m=s[j=i];
}
}
for(i=1;s[i];i++){
if(i==j)a=s[i]+a;
else if(i>j){
a+=s[i];
}else if(i<j){
if(s[i]>a[0])a+=s[i];
else a=s[i]+a;
}
}
cout<<a<<endl;
}
return 0;
}
hdu 4550的更多相关文章
- hdu 4550 卡片游戏 贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4550 题意:有n(n <= 100)个0~9之间的卡片,从左往右将卡片放到之前的卡片最左边或者最 ...
- hdu 4550 卡片游戏
http://acm.hdu.edu.cn/showproblem.php?pid=4550 贪心 #include <cstdio> #include <cstring> # ...
- hdu 4550 贪婪 思考题 权
http://acm.hdu.edu.cn/showproblem.php?pid=4550 想了挺久,然后各种分类 最终AC,假设是现场,对自己没信心的话,预计还是要WA,,,,,,然后搜题解,发现 ...
- hdu 模拟 贪心 4550
卡片游戏 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- SpringBoot集成Redis来实现缓存技术方案
概述 在我们的日常项目开发过程中缓存是无处不在的,因为它可以极大的提高系统的访问速度,关于缓存的框架也种类繁多,今天主要介绍的是使用现在非常流行的NoSQL数据库(Redis)来实现我们的缓存需求. ...
- akka设计模式系列-Backend模式
上一节我们介绍了Akka使用的基本模式,简单点来说就是,发消息给actor,处理结束后返回消息.但这种模式有个缺陷,就是一旦某个消息处理的比较慢,就会阻塞后面所有消息的处理.那么有没有方法规避这种阻塞 ...
- RocketMQ(2)
1. 消费端集群消费(负载均衡) 示例代码: /** * Producer,发送消息 * */ public class Producer { public static void main(Stri ...
- python爬虫之处理验证码
云打码实现处理验证码 处理验证码,我们需要借助第三方平台来帮我们处理,个人认为云打码处理验证码的准确度还是可以的 首先第一步,我们得先注册一个云打码的账号,普通用户和开发者用户都需要注册一下 然后登陆 ...
- 实现一个类似于收趣APP的功能
近日想做一个类似于收趣APP软件的一个功能,将头条.微信等其他App的文章能够通过分享微信好友的方式分享到自己的平台软件中. 分享的方式有三种: 1.通过微信好友的方式,将文章分享给收趣. 2.复制文 ...
- reactnative(1) - RefreshControl 使用案例
'use strict'; import React, { Component } from 'react'; import { AppRegistry, ScrollView, StyleSheet ...
- Python--10、生产者消费者模型
生产者消费者模型(★) 平衡生产线程和消费线程的工作能力来提高程序的整体处理数据的速度.程序中有两类角色:生产数据.消费数据实现方式:生产->队列->消费. 通过一个容器来解决生产者和消费 ...
- 在VirtualBox上安装Solaris 10全教程(包括下载)
您可以在博文的最下方留下评价, 也可以点击左边的 关注 来关注我的博客的最新动态. 如果文章内容对您有帮助, 不要忘记点击右下角的 推荐 来支持一下喔 如果您对博文有任何疑问, 可以通过评论或发邮件的 ...
- 【译】x86程序员手册14-5.1段转换
5.1 Segment Translation 段转换 Figure 5-2 shows in more detail how the processor converts a logical add ...
- 【译】x86程序员手册04 - 2.2数据类型
2.2 Data Types 数据类型 Bytes, words, and doublewords are the fundamental data types (refer to Figure 2- ...