Question description
Give you N numbers (n≤100), each number is between (0~1000), among which there are many
For complex numbers, please keep only one repeated number and arrange the remaining numbers from smallest to largest.
sequence and output.
Sample
Enter copy
10
20 40 32 67 40 20 89 300 400 15
output copy
8
15
20
32
40
67
89
300
400
Input
The input is
2
OK,
No.
1
Behavior
1
a positive integer, representing the number of numbers
:N
No.
2
OK
N
integers separated by spaces.
Output
No.
1
Behavior
1
positive integer
M
, represents the number of different numbers.
Next
M
Rows, each row has an integer, indicating that the order is different from small to large.
number.
#include <iostream> using namespace std; int main() { int a[200],b[200],n,lb; lb = 0; cin>>n; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { f = false; break; } } if(f==true) { b[lb] = a[i]; lb++; } } \t \t \t \t \t \t \t \t for(int i = 0;i<lb-1;i + + ) { for(int j = 0;j<lb-1-i;j + + ) { if(b[j]>b[j + 1]) { int t = b[j]; b[j] = b[j + 1]; b[j + 1] = t; } } } \t \t \t \t \t \t \t \t \t for(int i = 0;i<lb;i + + ) { cout<<b[i]<<" "; } return 0; }
teen programming
V 13201376357
Free games
Problem description
steam
Official anniversary celebration of the game platform, open for a limited time
30
Free download of games (number
1-30
)
Officials want to know which games have been downloaded
Sample
Enter copy
10
1 3 3 5 2 4 1 6 9 9
output copy
1 3 5 2 4 6 9
Input
The first line is an integer
n
Represents the total number of downloads
second line
n
integers represent
n
Number of game downloads
Output
1
Line, list of downloaded game numbers, separated by spaces
#include <iostream> using namespace std; int main() { int a[200],b[200],n,lb; lb = 0; cin>>n; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { f = false; break; } } if(f==true) { b[lb] = a[i]; lb++; } } \t \t \t \t\t \t \t \t \t for(int i = 0;i<lb;i + + ) { cout<<b[i]<<" "; } return 0; }
Vote
Problem description
Honor of Kings will select the most popular characters, and each character will have a number (
1-100
)
Please design a voting system that can display the number of times each character (corresponding number) appears
The display is sorted from largest to smallest number of votes. If the votes are equal, in no particular order
Sample
Enter copy
10
2 23 3 2 23 65 1 1 30 23
output copy
23 3
twenty two
3 1
65 1
30 1
Input
The first line is an integer
n
Number of delegate votes
second line
n
integers represent the voting character numbers
Output
n
Rows of two integers per row
The first number is the character number, and the second integer represents the number of votes received
#include <iostream> using namespace std; int main() { int a[200],b[200],c[200],n,lb; lb = 0; cin>>n; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = a[i]; lb++; } } \t \t \t \t\t \t \t \t \t for(int i = 0;i<lb;i + + ) { cout<<b[i]<<" "<<c[i]<<endl; } return 0; }
teen programming
V 13201376357
Poker Card Combinations
Problem description
Xiao Ming draws from a deck of playing cards (there is no king or king,
J
Think of it as a number
11
,
Q
yes
12
,
K
yes
13
,
A
yes
1
) withdraw
2
Play cards to sum up,
Please tell me how many unequal numbers can be combined and output these numbers from small to large. (
5.1.98
)
Sample
Enter copy
4
3 1 2 4
output copy
5
3 4 5 6 7
Input
The first line is an integer
n
represent(
n<=52
) total number of playing cards
second line
n
integers respectively represent the numerical value of the playing cards
Output
The first line is an integer
m
Represents the number of unequal numbers that can be combined.
second line
m
The numbers are separated by spaces to represent these
m
are not equal in order from smallest to largest
number.
#include <iostream> using namespace std; int main() { int a[200],b[200],c[200],n,lb; lb = 0; cin>>n; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { for(int j = i + 1;j<n;j + + ) { int s = a[i] + a[j]; bool f = true; for(int j = 0;j<lb;j + + ) { if(s==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = s; lb++; } } } \t \t \t \t \t \t \t for(int i = 0;i<lb-1;i + + ) { for(int j = 0;j<lb-1-i;j + + ) { if(b[j]>b[j + 1]) { int t = b[j]; b[j] = b[j + 1]; b[j + 1] = t; } } } \t \t \t\t \t \t \t \t cout<<lb<<endl; for(int i = 0;i<lb;i + + ) { cout<<b[i]<<" "; } return 0; }
Receive supplies for military training
Problem description
During military training, children can receive water cups of their favorite color (the colors are numbered
1-50
between)
The instructor wants to know which color is the most popular and how many have been received. Please program to help the instructor realize the function
Assume the most popular numbers are unique
Sample
Enter copy
10
1 4 2 6 2 9 1 9 9 8
output copy
9 3
Input
The first line, an integer
n
Represents how many people receive supplies
second line,
n
integers represent the color number that each person receives
Output
1
OK, get the color number and quantity with the largest quantity
The first integer represents the character number, and the second integer represents the quantity received
#include <iostream> using namespace std; int main() { int a[200],b[200],c[200],n,lb,max,maxi; lb = 0; cin>>n; max = 0; maxi = 0; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = a[i]; lb++; } } \t \t \t \t\t \t \t \t \t for(int i = 0;i<lb;i + + ) { if(c[i]>maxi) { maxi = c[i]; max = b[i]; } } cout<<max<<" "<<maxi; return 0; }
teen programming
V 13201376357
Find the mean, mode and median of N integers
Problem description
Find the mean, mode and median of N integers.
tips:
Mode
If there are 9 numbers: 17 13 17 9 17 17 3 16 17 17 appears the most times, which is this group of numbers.
the mode. (This question ensures that in the test data, there is only one number that appears the most)
Median
If there are 9 numbers: 102 170 96 90 97 106 110 182 100
After arranging these 9 numbers in a certain order (from large to small or small to large), we get:
182 170 110 106 102 100 97 96 90 The number in the middle is 102, 102 is this group
The median of the numbers.
And these 10 numbers: 106 99 104 120 107 112 33 102 97 100
Arranged in a certain order, we get: 120 112 107 106 104 102 100 99 97 33
There are two numbers in the middle: 104 102. The median is the average of these two numbers, that is
(104 + 102)/2 = 103.
Input
The first line is an integer N (5 <= N <= 10000) The second line is separated by spaces. N numbers Ai (0 <= Ai <= 100) Output
Output space-separated means and modes
Median (mean to two decimal places,
The median is rounded to one decimal place).
Sample
Enter copy
6
5 2 2 3 4 6
output copy
3.67 2 3.5
#include <iostream> #include <iomanip> using namespace std; int main() { float max,maxi,sum,pjs,zws; int n,a[5000],b[5000],c[5000],lb; lb = 0; cin>>n; max = 0; maxi = 0; sum = 0; for(int i = 0;i<n;i + + ) { cin>>a[i]; sum = sum + a[i]; } pjs = sum/n; cout<<fixed<<setprecision(2)<<pjs<<" "; \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = a[i]; lb++; } } \t \t \t \t \t for(int i = 0;i<lb;i + + ) { if(c[i]>maxi) { maxi = c[i]; max = b[i]; } } cout<<fixed<<setprecision(0)<<max<<" "; \t \t \t \t \t \t for(int i = 0;i<lb-1;i + + ) { for(int j = 0;j<lb-1-i;j + + ) { if(b[j]<b[j + 1]) { int t = b[j]; b[j] = b[j + 1]; b[j + 1] = t; t = c[j]; c[j] = c[j + 1]; c[j + 1] = t; } } } \t \t \t if(n%2==0) { int q = a[n/2]; int z = a[(n + 2)/2]; zws = (q + z)*1.0/2; } else if(n%2==1) { zws = a[(n + 1)/2]; } cout<<fixed<<setprecision(1)<<zws; \t \t\t \t \t \t \t \t return 0; }
Count the number of times scores appear
Problem description
After the exam is over, the teacher wants to know the children’s exam scores
Enter the whole class
n
For the scores of children’s shoes, please design a program to count the number of times each score appears.
Sample
Enter copy
10
90 99 100 99 80 60 60 70 90 60
output copy
90 2
99 2
100 1
80 1
60 3
70 1
Input
The first line is an integer
n
Represent the whole class
second line
n
Each integer represents the score of each student.
Output
n
Rows of two integers per row
The first number represents the score, and the second number represents the number of people with that score
? #include <iostream> using namespace std; int main() { int a[200],b[200],c[200],n,lb; lb = 0; cin>>n; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = a[i]; lb++; } } \t \t \t \t\t \t \t \t \t for(int i = 0;i<lb;i + + ) { cout<<b[i]<<" "<<c[i]<<endl; } return 0; } ?
teen programming
V 13201376357
Stamp Set
Problem description
Someone has m 3-cent stamps and n 5-cent stamps. How many different kinds of stamps can be obtained by using one or several of these stamps (or 0 stamps)?
The same postage greater than 0? Please find the total number of possible combinations of postage plans, and output all non-repeating postage plans greater than 0 in order from small to large.
case! (5.1.97)
For example: the possible postage combinations of 1 piece of 3 cents and 1 piece of 5 cents are as follows:
0 3 points + 1 5 points = 5 points
1 card 3 points + 0 cards 5 points = 3 points
1 card with 3 points + 1 card with 5 points = 8 points
Therefore, there are 3 possible solutions, and the sorted results are: 3 5 8!
Sample
Enter copy
twenty two
output copy
3 5 6 8 10 11 13 16
8
Input
Two integers, m and n, represent the number of 3-cent and 5-cent stamps respectively!
(1<=m,n<=100) Output
There are two lines of output. The first line outputs the different sizes that can be combined with these two stamps.
For a postage plan of 0, separate the numbers with spaces!
The second line outputs the total number of possible solutions
#include <iostream> using namespace std; int main() { int a[200],b[200],c[200],n,m,lb; lb = 0; cin>>m>>n; \t \t for(int i = 0;i<=m;i + + ) { for(int j = 0;j<=n;j + + ) { int s = 3*i + 5*j; bool f = true; for(int j = 0;j<lb;j + + ) { if(s==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = s; lb++; } } } \t \t \t \t \t \t \t for(int i = 0;i<lb-1;i + + ) { for(int j = 0;j<lb-1-i;j + + ) { if(b[j]>b[j + 1]) { int t = b[j]; b[j] = b[j + 1]; b[j + 1] = t; } } } \t \t \t\t \t \t \t \t for(int i = 1;i<lb;i + + ) { cout<<b[i]<<" "; } cout<<endl; cout<<lb-1; return 0; }
Free Games 2
Problem description
steam
Official anniversary celebration of the game platform, open for a limited time
30
Free download of games (number
1-30
)
The official wants to know which games have been downloaded and how many times they have been downloaded, please enter the number of downloads according to the game number
Sample
Enter copy
10
1 3 3 5 2 4 1 6 9 9
output copy
1:2
2:1
3:2
4:1
5:1
6:1
9:2
Input
The first line is an integer
n
Represents the total number of downloads
second line
n
integers represent
n
Number of game downloads
Output
n
OK,
Each line
2
An integer, representing the number of downloads of the game number level that has been downloaded
#include <iostream> using namespace std; int main() { int a[200],b[200],c[200],n,lb; lb = 0; cin>>n; for(int i = 0;i<n;i + + ) { cin>>a[i]; } \t \t for(int i = 0;i<n;i + + ) { bool f = true; for(int j = 0;j<lb;j + + ) { if(a[i]==b[j]) { c[j] + + ; f = false; break; } } if(f==true) { c[lb] = 1; b[lb] = a[i]; lb++; } } \t \t \t \t\t \t \t \t \t for(int i = 0;i<lb;i + + ) { cout<<b[i]<<":"<<c[i]<<endl; } return 0; }