Hdu 1042 N!

Source: Internet
Author: User

/*
Once wa n times, the error occurs at ① and must be supplemented at ②.
*/
# Include <cstdio>
# Include <cstring>
Const int nmax= 50000;
Struct BigNumber
{
Int data [nMax];
Int len;
BigNumber () {len = 1; memset (data, 0, sizeof (data ));}
BigNumber & operator = (const char * str );
BigNumber operator * (int a); // here, the multiplier only needs to be an integer.
Void print ();
Void clearLeadZero ();
} Ans;
Void BigNumber: clearLeadZero ()
{
While (len> 1 &&! Data [len-1]) len --;
}
BigNumber & BigNumber: operator = (const char * str)
{
Memset (data, 0, sizeof (data); // ②
Len = strlen (str );
Int I;
For (I = 0; I <len; ++ I)
Data [I] = str [len-I-1]-'0 ';
Return * this;
}
BigNumber: operator * (int)
{
Int q = 0;
BigNumber z;
Int I;
For (I = 0; I <len; ++ I)
// ① This is a positive solution, but for (I = 0; I <len; ++ I) then removes the while () loop and returns an error! The answer is at ②.
{
Int p = data [I] * a + q;
Z. data [I] = p % 10;
Q = p/10;
}
While (q)
{
Z. data [I ++] = q % 10;
Q/= 10;
}
Z. len = I;
Z. clearLeadZero ();
Return z;
}
Void BigNumber: print ()
{
Int I;
For (I = len-1; I> = 0; -- I)
Printf ("% d", data [I]);
Printf ("\ n ");
}
Int N;
Int main ()
{
// Freopen ("f: // data. in", "r", stdin );
// Freopen ("f: // data2.out", "w", stdout );
While (scanf ("% d", & N )! = EOF)
{
Ans = "1 ";
Int I;
For (I = 2; I <= N; ++ I)
Ans = ans * I;
Ans. print ();
}
Return 0;
}

 


From lhshaoren

Related Article

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.