题解 | Even? Odd?-牛客假日团队赛13D题

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

示例1

输入

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;
}


来源:xiydang
全部评论

相关推荐

07-02 18:09
门头沟学院 Java
苍穹外卖和谷粒商城这俩是不是烂大街了,还能做吗?
想去重庆的鸽子在吐槽:你不如把这俩做完自己搞明白再优化点再来问 何必贩卖焦虑
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务