P8044 [COCI2015-2016#4] YODA

[COCI2015-2016#4] YODA - 洛谷

属于数组的应用,倒序比对,比较简单,直接模拟

#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int N = 1e7;
vector<int> a, b;
bool flag1, flag2;
bool st1[N] = {true}, st2[N] = {true};

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    
    memset(st1, true, sizeof st1);
    memset(st2, true, sizeof st2);
    
    for(int i = s1.size() - 1; i >= 0; i -- )
        a.push_back(s1[i] - '0');
        
    for(int i = s2.size() - 1; i >= 0; i -- )
        b.push_back(s2[i] - '0');
    
    for(int i = 0; i < a.size() && i < b.size(); i ++ )
    {
        if(a[i] < b[i])
        {
            st1[i] = false;
        }
        else if(a[i] > b[i])
        {
            st2[i] = false;
        }
    }
    
    int x = 0, y = 0;
    for(int i = a.size() - 1; i >= 0; i -- )
    {
        if(st1[i])
        {
            flag1 = true;
            x = x * 10 + a[i];
        }
    }
    for(int i = b.size() - 1; i >= 0; i -- )
    {
        if(st2[i])
        {
            flag2 = true;
            y = y * 10 + b[i];
        }
    }
    
    
    if(flag1)
        cout << x << endl;
    else 
        cout << "YODA" << endl;
    if(flag2)
        cout << y << endl;
    else 
        cout << "YODA" << endl;
        
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值