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;
}

全部评论

相关推荐

行云流水1971:这份实习简历的优化建议: 结构清晰化:拆分 “校园经历”“实习经历” 板块(当前内容混杂),按 “实习→校园→技能” 逻辑排版,求职意向明确为具体岗位(如 “市场 / 运营实习生”)。 经历具象化:现有描述偏流程,需补充 “动作 + 数据”,比如校园活动 “负责宣传” 可加 “运营公众号发布 5 篇推文,阅读量超 2000+,带动 300 + 人参与”;实习内容补充 “协助完成 XX 任务,效率提升 X%”。 岗位匹配度:锚定目标岗位能力,比如申请运营岗,突出 “内容编辑、活动执行” 相关动作;申请市场岗,强化 “资源对接、数据统计” 细节。 信息精简:删减冗余表述(如重复的 “负责”),用短句分点,比如 “策划校园招聘会:联系 10 + 企业,组织 200 + 学生参与,到场率达 85%”。 技能落地:将 “Office、PS” 绑定经历,比如 “用 Excel 整理活动数据,输出 3 份分析表;用 PS 设计 2 张活动海报”,避免技能单独罗列。 优化后需强化 “经历 - 能力 - 岗位需求” 的关联,让实习 / 校园经历的价值更直观。 若需要进一步优化服务,私信
实习,投递多份简历没人回...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务