Digits Are Not Just Characters

Petrozavodsk Winter-2019. Japanese Contest-A.Digits Are Not Just Characters(模拟)

Problem A. Digits Are Not Just Characters
AOJ 1389:题面链接
题意:
给出初始字符串s0,然后给出N个询问,数字比字母小,两个字母间按照ascii码比较,两个十进制数字则按照大小排序。如果当前字符串按照此规则比s0小输出-,否则输出+;
思路:按照题意模拟,数字按照十进制存起来,比较大小就可
code:

//yyh
#include <iostream>
#include <cstring>
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <ctime>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <map>

#define INF 0x3f3f3f3f
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define per(i, n) for(int i=n;i>=0;i--)
#define rep2(i, n) for(ll i=1;i<=n;i++)
#define pb(x) push_back(x)
#define clint(x, n) memset(x,n,sizeof(x))
#define mp make_pair
#define fi first
#define se second
#define IO std::ios::sync_with_stdio(false)
#define ull unsigned long long
#define ud long double
#define pii pair<int,int>
#define random(x) (rand()%x)
using namespace std;
const ll inf = 0x3f3f3f3f;
const int mod = 998244353;
const int MAX = 123123;
const int N = 555;
const double eps = 1e-6;

inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

inline ll read1() {
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

ll max(ll a, ll b) {
    if (a > b) return a;
    return b;
}

ll min(ll a, ll b) {
    if (a < b) return a;
    return b;
}

ll multi(ll a, ll b, ll p)    //蹇€熶箻
{
    ll ans = 0;
    while (b) {
        if (b & 1LL) ans = (ans + a) % p;
        a = (a + a) % p;
        b >>= 1;
    }
    return ans;
}

ll pow_mod(ll a, ll b, ll p) {
    ll ans = 1;
    while (b) {
        if (b & 1LL) ans = multi(ans, a, p);
        a = multi(a, a, p);
        b >>= 1;
    }
    return ans;
}

int qpow(int a, int b) {
    int ans = 1, base = a;
    while (b != 0) {
        if ((b & 1) != 0)
            ans *= base;
        base *= base;
        b >>= 1;
    }
    return ans;
}

int lowbit(ll x) {
    return x & (-x);
}

int gcd(int a, int b) {
    return b > 0 ? gcd(b, a % b) : a;
}

const int maxn = 1e3 + 5;

//**************************************
bool cmp(string x, string y) {
    int i = 0, j = 0,p,q;
    string x1, y1;
    while (i < x.size() && j < y.size()) {
        p = 0, q = 0;
        x1 = "", y1 = "";
        int b;
        if (isdigit(x[i])) {
            b = 1;
            while (isdigit(x[i])) {
                x1 += x[i];
                i++;
            }
            int l = x1.size();
            for (int k = l - 1; k >= 0; k--) {
                p += (x1[k] - '0') * b;
                b *= 10;
            }
            x1 = "";
        } else if (x[i]>='A'&&x[i]<='z') {
            while (x[i]>='A'&&x[i]<='z') {
                x1 += x[i];
                i++;
            }
        }
        if (isdigit(y[j])) {
            b = 1;
            while (isdigit(y[j])) {
                y1 += y[j];
                j++;
            }
            int l = y1.size();
            for (int k = l - 1; k >= 0; k--) {
                q += (y1[k] - '0') * b;
                b *= 10;
            }
            y1 = "";
        } else if (y[j]>='A'&&y[j]<='z') {
            while (y[j]>='A'&&y[j]<='z') {
                y1 += y[j];
                j++;
            }
        }
        if (p != 0 && q != 0) {
            if (p > q)
                return true;
            else if (p == q)
                continue;
            else
                return false;
        }
        if (!x1.empty()) {
            if (!y1.empty()) {
                if (x1 > y1)
                    return true;
                else if (x1 == y1)
                    continue;
                else
                    return false;
            }
        }
        if (!x1.empty() && q != 0)
            return true;
        if (!y1.empty() && p != 0)
            return false;
    }
    if (i >= x.size() && j >= y.size())
        return false;
    if (i < x.size())
        return true;
    if (j < y.size())
        return false;
}

int main() {
    IO;
    int n;
    cin >> n;
    string s0;
    cin >> s0;
    string si;
    rep2(i,n) {
        cin >> si;
        if (cmp(s0, si))
            cout<<'-'<<endl;
        else
            cout<<'+'<<endl;
    }
    return 0;
}
全部评论

相关推荐

牛舌:如果我不想去,不管对方给了多少,我一般都会说你们给得太低了。这样他们就会给下一个offer的人更高的薪资了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务