zoukankan      html  css  js  c++  java
  • HZNU 2154 ldh发奖金【字符串】

    题目链接

    http://acm.hznu.edu.cn/OJ/problem.php?id=2154

    思路

    先判断不能拆分的情况
    以为需要拆分成两个正整数
    所以我们可以知道
    只有个位的数字 是不能够拆分的
    还有 类似于 100 1000000

    这种 在每个数位上 只有一个非0数字的 整数 也是不能够拆分的

    然后要考虑如何拆分

    其实我们容易想到
    数位越高 那么这个数字 就会越大
    我们应该要尽量 只拆除一个 个位数字 其他数字 从大到小 排列 组成另一个全新的数字

    因为 每一位都是可以随意交换的

    这样做对答案的贡献就最大

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = exp(1);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 1e4 + 5;
    const int MOD = 1e9 + 7;
    
    bool comp(char x, char y)
    {
        return x > y;
    }
    
    int main()
    {
        int t;
        scanf("%d", &t);
        while (t--)
        {
            string s;
            cin >> s;
            sort(s.begin(), s.end(), comp);
            int len = s.size();
            int vis;
            for (int i = len - 1; i >= 0; i--)
            {
                if (s[i] != '0')
                {
                    vis = i;
                    break;
                }
            }
            if (vis == 0)
                printf("Uncertain
    ");
            else
            {
                int num = s[vis] - '0';
                s.erase(vis, 1);
                len = s.size();
                for (int i = len - 1; i >= 0; i--)
                {
                    int temp = s[i] - '0';
                    num += temp;
                    s[i] = num % 10 + '0';
                    num /= 10;
                    if (num == 0)
                        break;
                }
                if (num)
                    cout << num;
                cout << s << endl;
            }
        }
    }
    
    
    
    
    
    
    
  • 相关阅读:
    邮件系列3 --- 安全传输
    配置postfix支持虚拟域和虚拟用户
    Postfix+Sasl+Courier-authlib+Dovecot+MySQL+extmail 邮件系统部署
    在switch中的case语句中声明变量编译出错的解决方案
    关于自控力
    PUTTY使用Ctrl+s僵死的问题
    sqlite3里类似top的用法
    二维数组、行指针、指针数组、二级指针
    sqlite3_exec函数的使用
    基于s5pv210嵌入式linux使用其他动态、静态库文件程序的交叉编译
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433159.html
Copyright © 2011-2022 走看看