Codeforces 908A (New Year and Counting Cards)914A(Perfect Squares)

题目时空门

Your friend has n cards.

You know that each card has a lowercase English letter on one side and a digit on the other.

Currently, your friend has laid out the cards on a table so only one side of each card is visible.

You would like to know if the following statement is true for cards that your friend owns: “If a card has a vowel on one side, then it has an even digit on the other side.” More specifically, a vowel is one of ‘a’, ‘e’, ‘i’, ‘o’ or ‘u’, and even digit is one of ‘0’, ‘2’, ‘4’, ‘6’ or ‘8’.

For example, if a card has ‘a’ on one side, and ‘6’ on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with ‘b’ and ‘4’, and for a card with ‘b’ and ‘3’ (since the letter is not a vowel). The statement is false, for example, for card with ‘e’ and ‘5’. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.

To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.

Input
The first and only line of input will contain a string s (1 ≤ |s| ≤ 50), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.

Output
Print a single integer, the minimum number of cards you must turn over to verify your claim.

Examples
input
ee
output
2
inputCopy
z
output
0
inputCopy
0ay1
output
2
Note
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.

In the second sample, we don’t need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.

In the third sample, we need to flip the second and fourth cards.

题意:

有一堆卡片,每张牌一面是数字一面是字母。题目给出了一个规则:只要牌面是元音字母则它的对照面一定是偶数,然后给你一个字符串,问最少翻多少张最终判断这些牌面对照是对的

思路:

根据题意知道:元音字母对应的一定是偶数,则他的逆反命题也成立,奇数一定对应的非元音字母。所以直接统计奇数和元音字母出现的次数即可。

代码:

#include<stdio.h>
#include<string.h>

char s[55];

int main()
{
    scanf("%s",s);
    int l=strlen(s);
    int sum=0;
    for(int i=0;i<l;i++)
    {
        if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='1'||s[i]=='3'||s[i]=='5'||s[i]=='7'||s[i]=='9')
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}

题目时空门

Given an array a1, a2, …, an of n integers, find the largest number in the array that is not a perfect square.

A number x is said to be a perfect square if there exists an integer y such that x = y^2.

Input
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array.

The second line contains n integers a1, a2, …, an ( - 106 ≤ ai ≤ 106) — the elements of the array.

It is guaranteed that at least one element of the array is not a perfect square.

Output
Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.

Examples
inputCopy
2
4 2
output
2
inputCopy
8
1 2 4 8 16 32 64 576
output
32
Note
In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.

题意:

给你了一个定义:如果满足x=y^2则称他为完美数。让你求给你的n个数中不是完美数的最大的数。

思路:

直接遍历。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;
const int N=1e5+10;
char s[2010][2010];

int f(int x)
{
    double y=sqrt(x);
    int xx=sqrt(x);
    if(y==xx)
        return 1;
    else
        return 0;
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        int x;
        int maxx=-1e6-10;
        for(int i=1;i<=n;i++)
        {
            cin>>x;
            if(!f(x))
            {
                if(maxx<x)
                    maxx=x;
            }
        }
        cout<<maxx<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Puppet__/article/details/79349771
今日推荐