hdu 4550 卡片游戏

http://acm.hdu.edu.cn/showproblem.php?pid=4550

贪心

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <queue>
 4 #include <string>
 5 #include <iostream>
 6 #include <algorithm>
 7 #define maxn 200
 8 using namespace std;
 9 
10 char str[200],s2[220];
11 int t;
12 string s1;
13 
14 int main()
15 {
16     scanf("%d",&t);
17     while(t--)
18     {
19         scanf("%s",str);
20         s1=str[0];
21         int j=0;
22         char ch='9';
23         for(int i=0; i<(int)strlen(str); i++)
24         {
25             if(str[i]!='0'&&str[i]<=ch)
26             {
27                 j=i;
28                 ch=str[i];
29             }
30         }
31         for(int i=1; i<(int)strlen(str); i++)
32         {
33             if(i==j) s1=str[i]+s1;
34             else if(i>j)
35             {
36                 s1+=str[i];
37             }
38             else if(i<j)
39             {
40                 if(str[i]<=s1[0])
41                 {
42                     s1=str[i]+s1;
43                 }
44                 else
45                 {
46                     s1+=str[i];
47                 }
48             }
49         }
50        cout<<s1<<endl;
51     }
52     return 0;
53 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/4046879.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值