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;
            }
        }
    }
    
    
    
    
    
    
    
  • 相关阅读:
    软工小白菜的团队介绍和采访
    团队作业第二次——团队Github实战训练
    团队作业第一次—团队展示和项目展示
    week5:Technology: Internets and Packets
    week3:History: The Web Makes it Easy to Use
    week2:History: The First Internet
    week4:History: Commercialization and Growth
    week1:History: Dawn of Electronic Computing
    第二日会议博客
    第一日会议博客
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433159.html
Copyright © 2011-2022 走看看