1.5 11: Number of integers

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

#include <iostream>
using namespace std;
int main()
{
    
    
	int k, times_1=0, times_5=0, times_10=0, temp;
	cin >>k;
	for(int i=0;i<k;i++)
	{
    
    
		cin>>temp;
		if(temp==1)
		{
    
    
			times_1++;
		}else if(temp==5)
		{
    
    
			times_5++;
		}else if(temp==10)
		{
    
    
			times_10++;
		}
	}
	cout<<times_1<<endl;
	cout<<times_5<<endl;
	cout<<times_10<<endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/yansuifeng1126/article/details/111994764