链接:
https://codeforces.com/problemset/problem/25/A
题意:
给定n个数,找出其中奇偶性不一样的那个数的位置
输入
5
2 4 7 8 10
输出量
3
输入
4
1 2 1 1
输出量
2
解:
原题中in evenness翻译正确(奇偶性上)基本没难度
每次输入时判断奇偶,找出第一个奇数和第一个偶数位置即可
实际代码:
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int j=0,jmao=0;
int o=0,omao=0;
for(int i=1;i<=n;i++)
{
int temp;
cin>>temp;
if(temp%2==0)
{
o++;
if(o==1) omao=i;
}
else
{
j++;
if(j==1) jmao=i;
}
}
if(j==1) cout<<jmao<<endl;
else if(o==1) cout<<omao<<endl;
}
限制:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output