我是靠谱客的博主 留胡子白开水,这篇文章主要介绍C语言Matrix编程题——[Arrays]D. Liang 6.7 Counting single digits,现在分享给大家,希望可以做个参考。

[Arrays]D. Liang 6.7 Counting single digits

Description:

Write a program that reads in n integers between 0 and 9 and displays the count for each number.

Input:

The first line is a positive integer t for the number of test cases.
Each test case contains two lines. The first line is an integer n (0<n<=100). The second line contains n integers between 0 and 9 .

Output:

For each test case, outputs each distinct number (in increasing order) and its count seperated by one blank in one line.

Sample Input:

复制代码
1
2
3
4
5
2 3 1 7 1 7 5 6 5 6 6 5 5

Sample Output:

复制代码
1
2
3
4
1 2 7 1 5 4 6 3

Programme:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Date:2020/4/26 //Author:Kamenrider Justice #include<stdio.h> void sort(); int main() { int n,num,i,j,k,flag;//n是运行的次数,num是输入的个数,flag判断有无相同数字 scanf("%d",&n); int number[100];//储存输入的数 for(i=0;i<n;i++) { int times[10]={0,0,0,0,0,0,0,0,0,0};//储存出现的次数,不初始化为0的话会出现乱值 scanf("%d ",&num); for(j=0;j<num;j++)//输入数字 { scanf("%d ",&number[j]); } for(j=0;j<num;j++) { flag=1; for(k=0;k<j;k++) { if(number[j]==number[k])//判断有无相同数字 { flag=0; } } if(flag) { times[number[j]]=1;//将该数字作为下标给times数组对应的位置赋值1 } else { times[number[j]]++;//增加次数 } } for(j=0;j<=9;j++)//输出部分 { if(times[j]!=0) { printf("%d %dn",j,times[j]); } } } return 0; }

Python数据分析与挖掘

最后

以上就是留胡子白开水最近收集整理的关于C语言Matrix编程题——[Arrays]D. Liang 6.7 Counting single digits的全部内容,更多相关C语言Matrix编程题——[Arrays]D.内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(90)

评论列表共有 0 条评论

立即
投稿
返回
顶部