Hdu_1013_digital Roots (Analog)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1013

Test instructions: Given a large number, it must be stored in an array, and then the sum of each bit is calculated, if less than 10 the output, if greater than 10, continue to seek it and the sum of each digit.

For example: 1000 9, and for 9000,9000>10, and then 9000 per digit and, the result is 9, in accordance with test instructions, then output.

<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <cstring>using namespace Std;char num[10000];int res (int n) {if (N < 10) return N;int i = 10;int total = 0;while (n/i) {total + = (n% i/(I/10)); i = i * 10;} Total + = n/(I/10); return res (total);} void f (char *n) {int len = strlen (num); for (int i = 0;i < len;i++) A[i] = num[i]-48;int total = 0;for (int i = 0;i < L en;i++) {total + = A[i];} cout << Res (total) << Endl;} int main (int argc, char *argv[]) {while (1) {cin >> num;if (num[0] = =) return 0;f (num);} return 0;} </span>


Hdu_1013_digital Roots (Analog)

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.