【C++编程基础】AOJ (C++ Programming II)—3-D-lexicograhical comparison

3-D-lexicograhical comparison

题目

Lexicographical Comparison Compare given two sequence A={a0,a1,…,an−1} and B={b0,b1,…,bm−1 lexicographically.
输入
The input is given in the following format. n a0 a1,…,an−1 m b0 b1,…,bm−1 The number of elements in A and its elements ai are given in the first and second lines respectively. The number of elements in B and its elements bi are given in the third and fourth lines respectively. All input are given in integers.
输出
Print 1 B is greater than A, otherwise 0.
样例输入
3
1 2 3
2
2 4

样例输出
1

题解(代码流程)

#include<bits/stdc++.h>
#include<iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++)cin >> A[i];
    cin >> m;
    vector<int> B(m);
    for (int i = 0; i < m; i++)cin >> B[i];
    cout << (A < B) << endl;//直接字典序比较
    return 0;
}

小结

学会简单的字典序比较,在题中是对数组A和B进行比较大小。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值