我是靠谱客的博主 留胡子白开水,最近开发中收集的这篇文章主要介绍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:

2
3
1 7 1
7
5 6 5 6 6 5 5

Sample Output:

1 2
7 1
5 4
6 3

Programme:

//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. Liang 6.7 Counting single digits所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部