洛谷P2995奇数偶数
題目描述
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那慘無人道的二年級老師搞了一個有 N 個正整數 I 的表叫Bessie去判斷“奇偶性”(這個詞語意思向二年級的學生解釋,就是“這個數是單數,還是雙數啊?”)。Bessie被那個表的長度深深地震驚到了,竟然跟棟棟的泛做表格一樣多道題!!!畢竟她才剛剛學會數數啊。
寫一個程序讀入N個整數,如果是雙數,那么在單立的一行內輸出"even",如果是單數則類似地輸出"odd".
輸入輸出格式
輸入格式:
?
* 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 輸出樣例#1:?
even odd
說明
Two integers: 1024 and 5931
1024 is eminently divisible by 2; 5931 is not
這個題有毒,請認真看一下是數據范圍(不過還是比較容易解決的)AC代碼如下:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() {int n,i,len; char c[65]; cin>>n;for(i=1;i<=n;i++){cin>>c; len=strlen(c); if((c[len-1]-'0')%2==0) cout<<"even\n";elsecout<<"odd\n";}return 0; }簡直有毒
轉載于:https://www.cnblogs.com/Michael666/p/10803085.html
總結
以上是生活随笔為你收集整理的洛谷P2995奇数偶数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洛谷P1880 [NOI1995]石子合
- 下一篇: js构造函数的浅薄理解