2014 title and reference of OJ in autumn C ++ week 18th, 2014oj

Source: Internet
Author: User
Tags cmath

2014 title and reference of OJ in autumn C ++ week 18th, 2014oj
The course homepage is in workshop.


1. Hundreds of BITs agreed

Description

M is a three-digit integer, and it is a little troublesome at home. The single-digit and ten-digit numbers have always been dissatisfied with the hundreds of-digit number. They have come up with a way to pick a hundred-digit number. The two of them first add and subtract a hundred digits, so they are proud of the positive result of the subtraction. The generous hundred bits agreed: It's not just to help these two boring guys. Compile a program to help them make a comparison.

Input

A three-digit integer m

Output

Result 1: The sum of the single digits and ten digits of m minus the hundred digits

Sample Input

293

Sample Output

10

HINT

#include <iostream>using namespace std;int main( ){    int m, a, b, c;    cin>>m;    a=m/100;    c=m%10;    b=(m%100)/10;    cout<<b+c-a<<endl;    return 0;}


2. Turn off the lights of the avengers

Description

Input n (1 ~ 500) Light and number, enter 1 ~ 9 (including numbers 1 and 9) m, drop the number with m in the number and m multiples of the lamp, and finally output the light number.

Input

Lamps n, numbers m

Output

Number of the remaining bright lights (each number occupies one line)

Sample Input

30 3

Sample Output

1

2

4

5

7

8

10

11

14

16

17

19

20

22

25

26

28

29

HINT

# Include <iostream> using namespace std; int main () {int t, m, n; cin> n> m; for (int I = 1; I <n; ++ I) // strictly speaking, I <n is wrong in this reference answer (positive I <= n )! Bad things are getting better. For more information, see the following description. {T = (I % m = 0) + (I % 10 = m) + (I/10) % 10 = m) + (I/100) % 10 = m); if (t = 0) cout <I <'\ n';} return 0 ;}
Note: Because the teacher made a mistake in answering the answer, the test data did not enable the n light that should be on. Many of you have tracked down the hidden test data. But from this question, let us once again realize the importance of the test boundary, or when there is a problem, we cannot find the problem in dealing with general conditions, first, we should realize whether there is a problem with the boundary (the boundary of this question is 1 and n. In fact, students who are aware of this should be able to adjust it in a timely manner. Another aspect of a bad thing is that when a question fails, does it affect the subsequent status? Exercise the psychological quality, which is also one of the improvements.

3. Avengers array score statistics

Description

Defines a two-dimensional array of five rows and three columns. Each row represents a student's high score, English score, and C ++ score. Define a one-dimensional array with five elements to store the average score of each student. Enter the score of each course, the score transcript with the average score, and the average score of all students.

Input

15 integers, indicating the scores of five students and three subjects

Output

The score and average score of each student are displayed in five rows.

Then display the average score of all students (retain two decimal places)

Sample Input

97 78 87

78 63 68

73 81 85

91 87 88

76 81 89

Sample Output

97, 78, 87, 87.33

78 63 68 69.67

73 81 85 79.67

91 87 88 88.67

76 81 89 82.00

81.47

HINT


# Include <iostream> # include <iomanip> using namespace std; int main () {int score [5] [3]; // double average [5] That saves the score array; // Save the average result array int I, j; double sum; // enter the result for (I = 0; I <5; I ++) for (j = 0; j <3; j ++) cin> score [I] [j]; // calculate the average score of each student and save it to the average array for (I = 0; I <5; I ++) {sum = 0; for (j = 0; j <3; j ++) sum + = score [I] [j]; average [I] = sum/3.0;} // output transcript cout with average score <setiosflags (ios: fixed) <setprecision (2 ); for (I = 0; I <5; I ++) {for (j = 0; j <3; j ++) cout <score [I] [j] <"; cout <average [I] <endl ;}// calculate the average value of the average score and output sum = 0; for (I = 0; I <5; I ++) sum + = average [I]; cout <sum/5.0 <endl; return 0 ;}

 

4. Find the prime number

Description

Enter several positive integers and output the prime numbers.

Please complete this question based on the following code and only submit the part you have written

# Include <iostream> # include <cmath> using namespace std; bool isPrime (int n); int main () {int n; while (cin> n) {if (isPrime (n) cout <n <endl;} return 0 ;}// the isPrime function is implemented below. The function is to determine whether n is a prime number. // If it is a prime number, true is returned. Otherwise, false is returned.

Input

A positive integer with an uncertain number

Output

The prime number in the input data, which is a number of rows in the original order.

Sample Input

83 5 12 363 137 307 31 87 126 490 300 28 358 239 69 25 94 7 286 ^ Z

Sample Output

83

5

137

307

31

239

7

 

HINT

#include <iostream>#include <cmath>using namespace std;bool isPrime(int n);int main( ){    int n;    while(cin>>n)    {        if(isPrime(n))            cout<<n<<endl;    }    return 0;} bool isPrime(int n){    bool prime=true;    int k=int(sqrt(n));    for(int i=2;i<=k;i++)    {        if(n%i==0)        {            prime=false;            break;        }    }    return prime;}


5. Bubble-teasing confidential messages

Description

The rule of confidentiality of A bulletin board message is to convert each English letter into the last 4th letters (which is very primitive), such as a to E and A to e. The last four letters (W, X, Y, Z or w, x, y, z) are changed to the first four letters (A, B, C, D or a, B, c, d ). non-letter characters remain unchanged. Enter a line of letters and the corresponding encrypted text must be output.

Input

One line of string

Output

Changed string

Sample Input

I am 20 years old.

Sample Output

M eq 20 cievw 7d.

HINT

 

Reference 1

#include <iostream>#include <cstdio>using namespace std;int main(){    char str[81];    gets(str);    int i=0;    while (str[i]!='\0')    {        if ((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))        {            str[i]=str[i]+4;            if ((str[i]>'Z'&&str[i]<='Z'+4)||(str[i]>'z'&&str[i]<='z'+4))                str[i]=str[i]-26;        }        i++;    }    puts(str);    return 0;}

Reference 2:

#include <iostream>#include <cstdio>using namespace std;int main(){    char c;    while ((c=getchar())!='\n')    {        if ((c>='a'&&c<='z')||(c>='A'&&c<='Z'))        {            c=c+4;            if ((c>'Z'&&c<='Z'+4)||(c>'z'&&c<='z'+4))                c=c-26;        }        cout<<c;    }    cout<<endl;    return 0;}


6. Use numbers to create numbers

Description

Enter a three-digit integer to calculate the difference between the sum of the two largest numbers and the sum of the smallest numbers. For example, input 8729, output 8, that is (9 + 8)-(2 + 7) = 8, and then input 24825, output 9, that is (8 + 5) -(2 + 2) = 9.

Input

An integer greater than three digits

Output

The difference between the sum of the two largest numbers and the sum of the smallest numbers

Sample Input

8729

Sample Output

8

HINT

Store the separated numbers in the array, and find the maximum, secondary, and minimum and secondary values from the array. The worst strategy is to sort the obtained array and take the first and last two elements.

# Include <iostream> using namespace std; int main () {int n, arr [15], num = 0; int I, max1, max2, min1, min2, t; cin> n; while (n> 0) {arr [num ++] = n % 10; n/= 10 ;} // find the largest and largest for (I = 0; I <num-1; I ++) // refer to the bubble sort idea, swap the maximum value to the final {if (arr [I]> arr [I + 1]) {t = arr [I]; arr [I] = arr [I + 1]; arr [I + 1] = t ;}} for (I = 0; I <num-2; I ++) // refer to the bubble sort idea, {if (arr [I]> arr [I + 1]) {t = arr [I]; arr [I] = arr [I + 1]; arr [I + 1] = t;} max1 = arr [num-1]; max2 = arr [num-2]; // find the largest and largest for (I = 0; I <num-1; I ++) // refer to the bubble sort idea, swap the minimum value to the final {if (arr [I] <arr [I + 1]) {t = arr [I]; arr [I] = arr [I + 1]; arr [I + 1] = t ;}} for (I = 0; I <num-2; I ++) // refer to the bubble sort idea, {if (arr [I] <arr [I + 1]) {t = arr [I]; arr [I] = arr [I + 1]; arr [I + 1] = t;} min1 = arr [num-1]; min2 = arr [num-2]; cout <max1 + max2-min1-min2 <endl; return 0 ;}

 

 







============================ Author he Lijian CSDN blog column ==================== ====|=== category directories of IT student growth guidance column columns (occasionally updated) ==||== C ++ online class column he Lijian Course Teaching Link (by course grade) ==|||== my book-"attacking the university against the normal energy passed to IT students" ==|==== paving the runway for IT cainiao to take off, A university that enjoys happiness and passion with its students ====

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.