[USACO09OCT]Even? Odd? G

Topic link

题目描述
Bessie’s cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive integers I (1 <= I <= 10^60) 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

Bessie's brutal second-grade teacher created a table with N positive integers I called Bessie to judge "parity" (the meaning of this term was explained to second-grade students, "Is this number singular or even?" ). Bessie was deeply shocked by the length of the table, there were as many questions as Dongdong's general table! ! ! After all, she just learned to count.

Write a program to read N integers, if it is a double number, then output "even" in a single line, if it is an odd number, output "odd" similarly.

Input format

  • Line 1: A single integer: N

  • Lines 2…N+1: Line j+1 contains I_j, the j-th integer to determine even/odd

Output format

  • Lines 1…N: Line j contains the word ‘even’ or ‘odd’, depending on the parity of I_j

Input and output sample
Input #1
2
1024
5931
Output #1
even
odd
Explanation/Prompt
Two integers: 1024 and 5931

1024 is eminently divisible by 2; 5931 is not

Code:

#include<iostream>
#include<cstring>
using namespace std;
char s[10000];
int main()
{
    
    
	long long int n, m;
	cin >> n;
	while(n--)
	{
    
    
		cin >> s;
		int len = strlen(s);
		m = s[len - 1];
		if(m % 2 == 0) cout << "even" << endl;
		else if(m % 2 == 1) cout << "odd" << endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113748068