本文主要是介绍nefuoj 7 计算整数个数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
计算整数个数
Problem:7
Time Limit:1000ms
Memory Limit:65536K
Description
给定k(k大于1且小于100)个正整数,其中每个数都是大于等于1,小于等于10的数。写程序计算给定的k个正整数中,1,5和10出现的次数。
Input
第一行包含一个正整数n,为输入测试数据的组数,下列n组数据中每组包括两行,第一行包含一个正整数k(k大于1且小于100),第二行包含k个正整数,每两个正整数用一个空格分开。
Output
输出有三个数,第一个数为1出现的次数,第二个数为5出现的次数,第三个数为10出现的次数且后面没有多于的空格,每个数间用一个空格隔开,每两组数据间用一空行分开。
Sample Input
3 5 1 5 8 10 5 4 1 5 2 2 9 8 7 1 5 10 7 5 1 1
Sample Output
1 2 1 1 1 0<span style="font-family: inherit; background-color: inherit;">3 2 1</span><br /><span id="_xhe_temp" width="0" height="0"><br /></span>#include <iostream>using namespace std;int main() {int n,k,a,b,c,data[101];cin>>n;while(n--){cin>>k;a=0;b=0;c=0;for(int i=0;i<k;i++)cin>>data[i];for(int i=0;i<k;i++){if(data[i]==1) a++;if(data[i]==5) b++;if(data[i]==10) c++;}cout <<a<<' '<<b<<' '<<c<< endl;}return 0; }
这篇关于nefuoj 7 计算整数个数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!