Digital amplification
Given an integer sequence and magnification x, each integer in the sequence is amplified by x times and output.
Time limit: 1000
Memory limit: 65536
input
It contains three lines: the first line N represents the length of the integer sequence (N ≤ 100); The second line is N integers (not exceeding the integer range), which are separated by a space; The third line contains an integer (not exceeding the integer range), which is the specified integer x.
output
N integers are the amplified sequence of the original sequence, and the integers are separated by a space.
sample input
3
1 5 7
2
sample output
2 10 14
Tip: pay attention to the data range of the answer
#include<iostream> using namespace std; int main() { int n,a[101],x; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } cin>>x; for(int i=1;i<=n;i++) { a[i]=a[i]*x; cout<<a[i]<<" "; } return 0; }
Unified file name
Small A often doesn't pay attention to case when naming files, and the format is chaotic. Now you are required to write A program to unify and standardize the format of the files in the directory, that is, if the first character of the file name is uppercase, the other letters are lowercase. For example, test and test are sorted into test.
Time limit: 1000
Memory limit: 65536
input
A number n on the first line indicates that there are n file names to be unified, and N does not exceed 100. The next N lines, one word per line, with a length of no more than 20, represent the name of the file. The file name consists of letters, numbers, and -.
output
n lines, one word per line, corresponding to the unified file name.
sample input
4
Test
data
2-TEST
problem-6
sample output
Test
Data
2-test
Problem-6
#include<bits/stdc++.h> using namespace std; int main() { int n; char a[101][20]; cin>>n; for(int i=0;i<=n;i++){ gets(a[i]); strlwr(a[i]); } for(int i=0;i<=n;i++){ if(a[i][0]>='a'&&a[i][0]<='z') a[i][0]-=32; puts(a[i]); } return 0; }
Sum of internal elements
Enter an integer matrix and calculate the sum of the elements inside the matrix. The so-called elements inside the matrix are the elements that are not in the first and last rows and the elements in the first and last columns.
Time limit: 1000
Memory limit: 65536
input
The first row is the row number m and column number n of the matrix (m < 100, n < 100), separated by a space. In the next M rows of data input, each row contains n integers (each number is greater than or equal to 0 and less than 1000), which are separated by a space.
output
Output the internal elements and of the corresponding matrix
sample input
3 3
3 4 1
3 7 1
2 0 1
sample output
7
#include<iostream> using namespace std; int main() { int m,n,a[101][101],sum=0; cin>>m>>n;//Number of rows and columns for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; if(i!=1&&j!=1&&i!=m&&j!=n) { sum+=a[i][j]; } } } cout<<sum; return 0; }
Integer sort
Given a sequence of 10 integers, it is required to reorder them. Sorting requirements:
1. Odd number comes first and even number comes last;
2. Odd numbers are sorted from large to small;
3. Even numbers are sorted in reverse order according to the input order.
Time limit: 1000
Memory limit: 65536
input
Enter a line containing 10 integers separated by a space. The range of each integer is greater than or equal to 0 and less than or equal to 100.
output
After sorting as required, output a line containing 10 sorted integers, separated by a space between numbers.
sample input
4 7 3 13 11 12 0 47 34 98
sample output
47 13 11 7 3 98 34 0 12 4
#include<bits/stdc++.h> using namespace std; int main() { int a[11],b[11]; for(int i=1;i<=10;i++){ cin>>a[i]; b[i]=a[i]; } sort(a+1,a+10+1); for(int i=10;i>=1;i--){ if(a[i]%2==1) cout<<a[i]<<" "; } for(int i=10;i>=1;i--){ if(b[i]%2==0) cout<<b[i]<<" "; } return 0; }
Calculate the number
If we convert a positive integer into a binary number, in this binary number, we call this kind of binary number in which the number of number 1 is more than the number of number 0 as good number.
For example:
(13) 10 = (1101) 2, where the number of 1 is 3 and the number of 0 is 1, then this number is a good number;
(10) 10 = (1010) 2, where the number of 1 is 2 and the number of 0 is also 2, then this number is not a good number;
(24) 10 = (11000) 2, where the number of 1 is 2 and the number of 0 is 3, then this number is not a good number;
For a given n, write a program to find a good number in 1 ~ n (including 1 and N).
Time limit: 1000
Memory limit: 65536
input
An integer, N in the title (n ≤ 1000)
output
An integer representing a good number from 1 to n (including 1 and N)
sample input
10
sample output
5
#include <bits/stdc++.h> using namespace std; bool good(int n){//The number of digits 1 is more than the number of digits 0 int s0=0,s1=0; while(n){ if(n%2==1) s1++; else s0++; n/=2; } if(s1>s0) return true; else return false; } int main(){ int cnt=0,n; cin>>n; for(int i=1;i<=n;i++){ if(good(i)) cnt++; } cout<<cnt; return 0; }