列表

详情


NC24844. [USACO 2009 Oct G]Even? Odd?

描述

Bessie's cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive integers I (1 <= I <= ) 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 I_j, the j-th integer to determine even/odd

输出描述

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

示例1

输入:

2 
1024 
5931 

输出:

even
odd

说明:

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

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 4ms, 内存消耗: 496K, 提交时间: 2020-02-17 21:32:32

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,a;
	char b[100000];
	cin>>N;
	while(N--)
	{
		cin>>b;
		a=b[strlen(b)-1]-'0';
		if(a%2==0)
		cout<<"even\n";
		else
		cout<<"odd\n";
	}
}

Pascal(fpc 3.0.2) 解法, 执行用时: 2ms, 内存消耗: 256K, 提交时间: 2019-08-30 09:13:14

var
i,n,a:longint;
s:string;
begin
readln(n);
for i:=1 to n do
 begin
  readln(s);
  if odd(ord(s[length(s)])) then writeln('odd') else writeln('even');
 end;
end.

Python3(3.5.2) 解法, 执行用时: 34ms, 内存消耗: 3344K, 提交时间: 2019-08-30 10:07:20

for t in range(int(input())):print('odd' if int(input()) % 2 else 'even')

上一题