PTA L1-022 奇偶分家 (10 分)

版权声明:转载请附上原文链接哟! https://blog.csdn.net/weixin_44170305/article/details/89707344

上天折断了你飞翔的羽翼,你也要给自己一双翅膀!

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

输入格式:

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

输出格式:

在一行中先后输出奇数的个数、偶数的个数。中间以1个空格分隔。

输入样例:

9
88 74 101 26 15 0 34 22 77

输出样例:

3 6
#include<cstdio>
#include<iostream>
int a[1005];
using namespace std;
int main()
{
    int n,t1=0,t2=0;
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2==1)
        t1++;
    else
        t2++;
    }
    cout<<t1<<' '<<t2;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44170305/article/details/89707344