Week 6 OJ Test Project 6-use numbers to create numbers, oj6 --

Source: Internet
Author: User

Week 6 OJ Test Project 6-use numbers to create numbers, oj6 --

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.

The Code is as follows:

# Include <iostream> using namespace std; int main () {int str [10]; int I = 0, n, m, j, t; cin> n; do {str [I ++] = n % 10; n = n/10;} while (n! = 0); m = I; for (I = 0; I <m-2; I ++) {for (j = 0; j <m-1-I; j ++) {if (str [j]> str [j + 1]) {t = str [j]; str [j] = str [j + 1]; str [j + 1] = t ;}} cout <(str [M-1] + str [m-2]) -(str [1] + str [0]); return 0 ;}


 

Running result:

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.