洛谷 P2955 [USACO09OCT]奇数偶数Even? Odd?【字符串/易错】
题目描述
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
输入输出样例
说明
Two integers: 1024 and 5931
1024 is eminently divisible by 2; 5931 is not
【代码】:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
char a[1005];//是大数 用字符串
cin>>n;
while(n--)
{
scanf("%s",a);
if((a[strlen(a)-1]-'0')%2==0)//判断奇偶只要看最后一位
puts("even");
else
puts("odd");
}
return 0;
}
洛谷 P2955 [USACO09OCT]奇数偶数Even? Odd?【字符串/易错】的更多相关文章
- P2955 [USACO09OCT]奇数偶数Even? Odd?
题目描述 Bessie's cruel second grade teacher has assigned a list of N (1 <= N <= 100) positive int ...
- 题解 P2955 【[USACO09OCT]奇数偶数Even? Odd? 】
很明显这题是个假入门! 小金羊一不小心点进题解发现了内幕 能看的出来都WA过Unsigned long long int 做题可以用Python,Python的变量虽然 强悍的不行! 但是我们可以用字 ...
- 洛谷P3832 [NOI2017]蚯蚓排队 【链表 + 字符串hash】
题目链接 洛谷P3832 题解 字符串哈希然后丢到hash表里边查询即可 因为\(k \le 50\),1.2操作就暴力维护一下 经复杂度分析会发现直接这样暴力维护是对的 一开始自然溢出WA了,还以为 ...
- 洛谷 P2376 [USACO09OCT]津贴Allowance 解题报告
P2376 [USACO09OCT]津贴Allowance 题目描述 作为创造产奶纪录的回报,\(Farmer\) \(John\)决定开始每个星期给\(Bessie\)一点零花钱. \(FJ\)有一 ...
- 洛谷——P2958 [USACO09OCT]木瓜的丛林Papaya Jungle
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer ...
- 洛谷—— P1339 [USACO09OCT]热浪Heat Wave
P1339 [USACO09OCT]热浪Heat Wave 题目描述 The good folks in Texas are having a heatwave this summer. Their ...
- 洛谷 P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll
P2959 [USACO09OCT]悠闲漫步The Leisurely Stroll 题目描述 Bessie looks out the barn door at the beautiful spri ...
- 洛谷 P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed
P2960 [USACO09OCT]Milkweed的入侵Invasion of the Milkweed 题目描述 Farmer John has always done his best to k ...
- 洛谷 P2958 [USACO09OCT]木瓜的丛林Papaya Jungle
P2958 [USACO09OCT]木瓜的丛林Papaya Jungle 题目描述 Bessie has wandered off the farm into the adjoining farmer ...
随机推荐
- 设置苹果手机input按钮和button按钮颜色显示问题
网页上,尽管设置了input按钮和button的背景颜色,但在苹果手机上测试时仍会发现背景颜色为透明渐变色,不起作用,怎么解决呢? 在css公共样式中加上下面代码就可以解决,去除button和inpu ...
- js如何往数组Array中添加元素 (2013-09-04 10
unshift:将参数添加到原数组开头,并返回数组的长度 pop:删除原数组最后一项,并返回删除元素的值:如果数组为空则返回undefined push:将参数添加到原数组末尾,并返回数组的长度 co ...
- 01.Hibernate快速入门
第一步:下载Hibernate5的运行环境 https://sourceforge.net/projects/hibernate/files/hibernate-orm/ 第二步:在数据库创建表 Cr ...
- Odoo Documentation : Environment
Environment The Environment stores various contextual data(上下文数据 ) used by the ORM: the database cur ...
- 路由的配置,侧边栏类名与url的结合运用
var url_array = document.location.pathname.split("/"); s1 = url_array[1]; s2 = url_array[2 ...
- 装配SpringBean(三)--XML方式实例
前一篇文章中已经介绍了XML方式装配bean的方式,本文将综合这些方式举一个实例并进行测试,我会把所有类型的参数都放在同一个类中进行测试,下面是我的类结构: 上图是我画的一个基本结构,可以看出该类中有 ...
- Elasticsearch快速开始
Elasticsearch是一个分布式RESTful风格的搜索和数据分析引擎 查询:Elasticsearch允许执行和合并多种类型的搜索——结构化.非结构化.地理位置.度量指标.搜索方式随心而变 分 ...
- css3新特性概览
一.特性 1.强大的选择器 2.半透明度效果的实现 3.多栏布局 4.多背景图 css3允许背景属性设置多个属性值,如:background-image,background-repeat,backg ...
- tensorflow高效地推导pb模型,完整代码
from matplotlib import pyplot as plt import numpy as np import os import six.moves.urllib as urllib ...
- SSH免密登录设置
******配置主机之间的免密ssh登陆 假如 A 要登陆 B 在A上操作: (1)首先生成密钥对 ssh-keygen (提示时,直接回车即可) (2)再将A自己的公钥拷贝并追加到B的授权列 ...