题目描述
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
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
输入
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; }
来源:xiydang