oj:004: the number of integers (basic questions)

004: Number of integers
View and submit statistical questions
Total time limit: 1000ms Memory limit: 65536kB
Description
Given k (1
<k <100) positive integers, each of which is a number greater than or equal to 1 and less than or equal to 10. Write a program to calculate the number of occurrences of 1, 5 and 10 in the given k positive integers.

Input
There are two lines of input: the first line contains a positive integer k, the second line contains k positive integers, and every two positive integers are separated by a space.
Output The
output has three lines, the first line is the number of occurrences of 1, the second line is the number of occurrences of 5, and the third line is the number of occurrences of 10.
Sample input
5
1 5 8 10 5
Sample output
1
2
1
Source
Introduction to Calculation 05-Mock Exam 1

Solution: First enter the number of this group of numbers, then enter the content of this group of numbers, and judge the number of the same number as the three numbers 1 5 10 according to the content.
Thought: judge separately, output separately


#include<iostream>
using namespace std;
int main()
{
    
    int k,a[100];
int m=0,n=0,p=0;
cin >> k;
for(int i=1;i<=k;i++)
{
    
    
cin >> a[i];
if(a[i]==1)
m++;
if(a[i]==5)
n++;
if(a[i]==10)
p++;
}
cout<<m<<endl;
cout<<n<<endl;
cout<<p<<endl;
return 0;
}


Guess you like

Origin blog.csdn.net/qq_51082388/article/details/112974988