您的位置:首页 > 其它

团体程序设计天梯赛L1-022 奇偶分家

2017-03-22 17:48 225 查看


L1-022. 奇偶分家

时间限制

400 ms

内存限制

65536 kB

代码长度限制

8000 B

判题程序

Standard

作者

陈越

给定N个正整数,请统计奇数和偶数各有多少个?

输入格式:

输入第一行给出一个正整N(<= 1000);第2行给出N个正整数,以空格分隔。

输出格式:

在一行中先后输出奇数的个数、偶数的个数。中间以1个空格分隔。
输入样例:
9
88 74 101 26 15 0 34 22 77

输出样例:
3 6


——————————————————————————————————————

对于输入的数直接处理,直接记录奇数或偶数的个数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f

int main()
{
int n,s;
scanf("%d",&n);
int a=0,b=0;
for(int i=0;i<n;i++)
{
scanf("%d",&s);
if(s%2==0)
b++;
else
a++;
}
printf("%d %d\n",a,b);

return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: