Statistics of VIP number trained by Lanqiao Cup algorithm

Topic 1633: [Blue Bridge Cup] [Algorithm Training VIP] Statistics

                        时间限制: 1Sec 内存限制: 128MB 提交: 420 解决: 379
                
            

            

            
                题目描述
                在一个有限的正整数序列中,有些数会多次重复出现在这个序列中。 

Such as the sequence: 3, 1, 2, 1, 5, 1, 2. Among them, 1 appears 3 times, 2 appears twice, 3 appears once, and 5 appears once.

Your task is to output the number of occurrences and the number of occurrences in the sequence from small to large for a given sequence of positive integers.

Data size and convention

Data: n<=1000; 0<x<=1000,000.

                输入
                第一行正整数n,表示给定序列中正整数的个数。 

The second line is n positive integers x separated by spaces, representing the given sequence.

                输出
                若干行,每行两个用一个空格隔开的数,第一个是数列中出现的数,第二个是该数在序列中出现的次数。 

Sample input
12
8 2 8 2 2 11 1 1 8 1 13 13

Sample output
1 3
2 3
8 3
11 1
13 2

#include<iostream>
#include<algorithm>
#define MAX 1005
using namespace std;
int main()
{
    
    
 int str[MAX];
 int len=0;
 int a;
 cin>>a;// 这就是个摆设 
 while(scanf("%d",&str[len++])!=EOF);
 len=len-1; 
 sort(str,str+len,less<int>());
 for(int i=0;i<len;i++)
 {
    
    
  cout<<str[i]<<' ';
  int cns=1; 
  while(str[i+1]==str[i])
  {
    
    
   cns++;
   i++;
  }
  cout<<cns<<endl;
  } 
 return 0;
 } 

Guess you like

Origin blog.csdn.net/qq_46232829/article/details/107895754