Pat---1005. spell it right (20)

Source: Internet
Author: User
Tags array definition

# Include <iostream> # include <stack> # include <string. h> char * g_wordtable [10] = {"zero", "one", "two", "three", "four", "five", "Six ", "Seven", "eight", "Nine "};

Int main () {// The Char input [1000] that stores user input data; // when user input data is not stopped while (scanf ("% s ", & input )! = EOF) {int sum = 0; // obtain the length of user input data, using string. h int Len = strlen (input); // convert each character into an ascii code. The ASCII code of a number character is equal to the number itself, and the sum is for (INT I = 0; I <Len; ++ I) sum + = (input [I]-'0'); // defines a stack STD: Stack <int> S; // split the bit. The bit is first put into the stack, and then there are ten hundred do {int temp = sum % 10; S. push (temp); sum/= 10;} while (sum! = 0); // output, empty determines whether the stack is empty while (! S. empty () {// obtain the data int T = s on the top of the stack. top (); // size returns the current stack length (that is, the number of internal data) // if the size of the stack is greater than 1 if (INT) s. size ()> 1) printf ("% s", g_wordtable [T]); else printf ("% s \ n", g_wordtable [T]); // pop pops up the element S at the top of the stack. pop () ;}} return 0 ;}

Conclusion: 1. Better understanding of pointer array definition strings and two-dimensional array definition strings

2. Measure the test taker's knowledge about how to split items.

3. Master the stack method

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.