zoukankan      html  css  js  c++  java
  • 2018-12-15 acm日常 CodeForces

    B - Problem B CodeForces - 25A

    Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.

    Input
    The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.

    Output
    Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.

    Examples
    Input
    5
    2 4 7 8 10
    Output
    3
    Input
    4
    1 2 1 1
    Output
    2
    题目大意:一组数只有一个奇数或者偶数,输出它的位置

    思路:建立一个数组放数字,然后对偶数/奇数进行计数,若个数为一,则记录其下标。

    #include<iostream>
    using namespace std;
    
    int main()
    {
    	int a[105];
    	int n, x=0, y=0, temp1, temp2;
    	cin >> n;
    	for (int i=0; i < n; i++)
    	{
    		cin >> a[i];
    		if (a[i] % 2 == 0)
    		{
    			x++;
    			if (x==1)
    			{
    				temp1 = i;
    			}
    			else
    			{
    				temp1 = -1;
    			}
    
    		}
    		else
    		{
    			y++;
    			if (y == 1)
    			{
    				temp2 = i;
    			}
    			else
    			{
    				temp2 = -1;
    			}
    		}
    
    	}
    	if (temp1>-1)
    		cout << temp1+1;
    	if (temp2>-1)
    		cout << temp2+1;
        return 0;
    }
    
    
  • 相关阅读:
    Html中,id、name、class、type的区别
    Windows10右键添加“在此处打开命令窗口”
    yarn的安装与使用及与npm对应的命令
    TodoMVC:帮助你选择一个MV*框架
    迅速上手:使用taro构建微信小程序基础教程
    编程之性能优化知多少
    CQRS
    事件驱动之异步事件
    事件驱动下
    事件驱动上
  • 原文地址:https://www.cnblogs.com/gidear/p/10433290.html
Copyright © 2011-2022 走看看