题解 | 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-18 15:02
门头沟学院 Java
刚打开网申页面就不想填了,还是不要为难自己了
poppinzhan...:多益老行业毒瘤了,碰到徐波这种恶心的烂人,去了也是受罪。
点赞 评论 收藏
分享
最近拿到了正浩的提前批offer感觉自己的实力得到了肯定,也给了我更多底气
搞机墨镜猫:正浩提前批官网好像就只有电力电子软硬件,哥们投的是这两个岗位吗
26届校招投递进展
点赞 评论 收藏
分享
07-11 22:27
中南大学 Java
程序员牛肉:学历的话没问题。但是没问题的也就只有学历了。 其实你的整体架构是正确的,博客接着干。但是项目有点过于简单了。从后端的角度上讲,你这也就是刚入门的水平,所以肯定约面试够呛。 如果你要应聘后端岗位,那你第一个项目竟然是仿写操作系统。这个你要面试官咋问你。你一定要记住一点,你简历上写的所有的东西,都是为了证明你有能力胜任当前的岗位,而不是为了证明你自己会什么。 如果你只是浅浅的做几个项目,描述也都是烂大街。技术点也都是各种混水类的配置类需求,那你就不要幻想自己能走多远。一定要保持思考,保持学习。
点赞 评论 收藏
分享
05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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