The number of the same number as the specified number - the key is how to input a line of integers and store them in the array

Total time limit: 1000ms Memory limit: 65536kB
Description
Outputs the number of integers that are the same as the specified number.

Input The
input consists of three lines:
the first line is N, which represents the length of the integer sequence (N <= 100);
the second line contains N integers, separated by a space;
the third line contains an integer, which is the specified integer m .
Output
Output is the number of N numbers that are the same as m.
Sample Input
3
2 3 2
2
Sample Output

#include<iostream>
#include<cstdio>
using namespace std;
int main (){
    int N,a[100],b,s=0;
    cin >> N;
    int i =0;
    while (scanf("%d", &a[i++]))
    {
        if (getchar() == '\n')
            break;
    }
    cin >> b;
    for(int j =0;j<N;j++)
    {
    if (a[j] == b)
       s=s+1;
    }

    printf("%d",s);
    return 0;
}

Tao Tao's Apple Picking
Description
There is an apple tree in Tao Tao's yard. Every autumn, the tree will bear 10 apples. When the apples are ripe, Tao Tao will go to pick apples. Tao Tao has a bench that is 30 centimeters high. When she can't pick apples with her hands, she steps on the bench and tries again.

Now that you know the height of 10 apples to the ground, and the maximum height that Taotao can reach when she stretches her hand straight, please help Taotao to count the number of apples she can pick. Suppose she touches the apple, and the apple will fall.

The input
consists of two lines of data. The first line contains 10 integers (in centimeters) between 100 and 200 (including 100 and 200) representing the height of 10 apples to the ground, and two adjacent integers are separated by a space. The second line contains only an integer (in centimeters) between 100 and 120 (inclusive), indicating the maximum height that Tao Tao can reach when his hand is straight.
The output
consists of a single line containing only an integer representing the number of apples that Tao Tao can pick.
Sample input
100 200 150 140 129 134 167 198 200 111
110
Sample output
5

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a[10];
    int b,s=0;
    int i =0;
    while (scanf("%d", &a[i++]))
    {
        if (getchar() == '\n')
            break;
    }
    cin >> b;
    for(int j =0;j<10;j++)
    {
    if (a[j] <= b || a[j] <= b+30)
       s=s+1;
    }

    printf("%d",s);
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324584614&siteId=291194637