2 条题解

  • 0
    @ 2025-9-29 11:12:35

    C语言版本:

    #include <stdio.h>
    int main(){
          long long a,b;
          scanf("%lld %lld",&a,&b);
          if(a%2==0 && b%2==1)
          {
                if(a>b) printf("2");
                else if(a<b) printf("1");
          }
          else if(a%2==1 && b%2==0)
          {
                if(a>b) printf("1");
                else if(a<b) printf("2");
          }
          return 0;
    }
    

    C++版本:

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main(){
        long long a,b; cin >> a >> b;
        if(a&1){
            if(a>b){
                cout << 1 << endl;
            }else{
                cout << 2 << endl;
            }
        }else{
            if(a>b){
                cout << 2 << endl;
            }else{
                cout << 1 << endl;
            }
        }
    }
    

    考察点:

    1. 数据范围 a<= 1e18,要使用long long
    2. 分类讨论模拟
    • 0
      @ 2025-9-28 20:59:22
      #include <stdio.h>
      int main(){
      	long long int a,b;
      	scanf("%lld%lld",&a,&b);
      	if(a%2==0){
      		long long int temp=a;
      		a=b;
      		b=temp;
      	}
      	if(a>b) printf("1\n");
      	else if(a<b) printf("2\n");
      }
      
      
      • 1

      信息

      ID
      1122
      时间
      1000ms
      内存
      256MiB
      难度
      8
      标签
      (无)
      递交数
      542
      已通过
      77
      上传者