1. #include <bits/stdc++.h>
    2. using namespace std;
    3. // 求素数(质数)
    4. bool is_prime(int n){
    5. if(n < 2) return false;
    6. // 1000*1000 = 100000000;
    7. for(int i= 2 ; i*i <= n; i++){
    8. if(n % i == 0) return false;
    9. }
    10. return true;
    11. }
    12. // 是否回文
    13. bool is_pol(int n){
    14. int sourceNum = n;
    15. int targetNum = 0;
    16. while(n > 0){
    17. targetNum = targetNum * 10 + n % 10;
    18. n /= 10;
    19. }
    20. // return targetNum == sourceNum ? true : false;
    21. return targetNum == sourceNum ;
    22. }
    23. bool is_pol2(int n){
    24. string s = to_string(n);
    25. return s == reverse(s);
    26. }

    字典序求最值

    https://oj.yecheng.tv/p/J213

    1. #include <bits/stdc++.h>
    2. using namespace std;
    3. string friMIN="1300",lstMAX="0000";
    4. string friName = "" ,lstName = "";
    5. void check(){
    6. string name,m,d,bir;
    7. cin>> name >> m >> d;
    8. bir = m + d; // 文本拼接
    9. if(friMIN > bir){
    10. friMIN = bir;
    11. friName = name;
    12. }
    13. if(lstMAX < bir){
    14. lstMAX = bir;
    15. lstName = name;
    16. }
    17. }
    18. int main(){
    19. // 数据录入
    20. int n;
    21. cin >> n;
    22. while(n--){
    23. check();
    24. }
    25. cout << friName << " " << lstName;
    26. return 0;
    27. }