Even? Odd? G

思路

根据题意可知,计算机中没有任何一种整数类型可以表示长度为60的数字,所以考虑用字符串来读取这个数值,然后根据偶数的特点:最后一位数字是偶数来解决这个问题

代码

#include<iostream>
using namespace std;

int main(){
    string str;
    int n;
    cin>> n;
    for(int i=1;i<=n;++i){
        cin>>str;
        int len=str.length();
        if(str[len-1]=='2'||
            str[len-1]=='4'||
            str[len-1]=='6'||
            str[len-1]=='8'||
            str[len-1]=='0') cout<<"even"<<endl;
        else cout<<"odd"<<endl;
    }
    return 0;
}
posted @ 2025-01-23 15:53  Buy-iPhone  阅读(6)  评论(0)    收藏  举报