alt

思路 :模拟 加 贪心

看数据范围极其大, 肯定是不能将字符串转为整数来比较的, 而且题目保证给出的是不含前导0的数字,那么就有以下的贪心策略:给你两个字符串a,.若a.size() > b.size() 则a 一定大于 b, 反之a.size() < b.size() b 一定大于 a; 若a.size == b.size() 那么就每一位进行比较, 若某一字符串某一位小于另一字符串某一位则直接输出 某个字符串 is stronger,若每一位都相同输出equal

#include<bits/stdc++.h>
using namespace std;
int main(){
    string a, b;
    cin >> a >> b;
    if(a.size() > b.size()){//a的数位大
        cout << "a is stronger";
        return 0;
    } else if(a.size() < b.size()){//b的数位大
        cout << "b is stronger";
        return 0;
    } else{//数位相同
        int n = 0;
        while(n < a.size()){//比较到末尾
            if(a[n] > b[n]){
                cout << "a is stronger";
                return 0;
            } else if(a[n] < b[n]){
                cout << "b is stronger";
                return 0;
            }
            n++;
        }
    }
    cout << "equal";
}