UVa 484 - The Department of Redundancy Department

题目:统计每个数字出现的次数。

分析:简单题。直接储存计数即可。

注意:没有数据范围o(╯□╰)o。

#include 
#include 
#include 

int number[10000];
int counts[10000];

int main()
{
	int n,count = 0,find;
	while ( ~scanf("%d",&n) ) {
		find = 0;
		for ( int i = 0 ; i < count ; ++ i )
			if ( number[i] == n ) {
				counts[i] ++;
				find = 1;
				break;
			}
		if ( !find ) {
			number[count ++] = n;
			counts[count -1] = 1;
		}
	}
	for ( int i = 0 ; i < count ; ++ i )
		printf("%d %d\n",number[i],counts[i]);
	
	return 0;
}


你可能感兴趣的:(入门题,解题报告)