Even? Odd?

链接:https://ac.nowcoder.com/acm/contest/1082/D
来源:牛客网
 

题目描述

Bessie's cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive integers I (1 <= I <= 106010^{60}1060) for which Bessie must determine their parity (explained in second grade as 'Even... or odd?'). Bessie is overwhelmed by the size of the list and by the size of the numbers. After all, she only learned to count recently.
Write a program to read in the N integers and print 'even' on a single line for even numbers and likewise 'odd' for odd numbers.
POINTS: 25

输入描述:

 

* Line 1: A single integer: N

* Lines 2..N+1: Line j+1 contains IjI_jIj​, the j-th integer to determine even/odd

输出描述:

* Lines 1..N: Line j contains the word 'even' or 'odd', depending on the parity of IjI_jIj​

示例1

输入

复制

2 
1024 
5931 

输出

复制

even
odd

说明

Two integers: 1024 and 5931
1024 is eminently divisible by 2; 5931 is not

 

思路:此题是判断一个数是不是偶数,但是这个数比较大(不大于10的6次方),可以选择用字符串读取该数字,然后判断最后一个字符的奇偶性就可以了;

 

代码:

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    char num[100];
    scanf("%d", &n);
    for(int i= 0; i < n; i++){
        scanf("%s", num);
        int len = strlen(num) - 1;
        if((num[len]- '0')% 2 == 0)
            printf("even\n");
        else
            printf("odd\n");

    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值