CF1311A Add Odd or Subtract Even

Solution

a<b, delta=odd, ans=1

a<b, delta=even, ans=2

a=b ans=0

a>b, delta=odd, ans=2

a>b, delta=even, ans=1

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

signed main() {
    int t,a,b;
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>a>>b;
        if(a<b) {
            if((b-a)%2) cout<<1<<endl;
            else cout<<2<<endl;
        }
        else if(a==b) cout<<0<<endl;
        else {
            if((b-a)%2) cout<<2<<endl;
            else cout<<1<<endl;
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/mollnn/p/12372846.html