Problem20

#include <iostream>
#include <string>
using namespace std;

#define NUM 100

void
multi(string *ps, int num)
{
    string s("");
    int    c = 0;
    for (string::size_type i = ps->size(); i > 0; i--)
    {
        int n = (ps->at(i-1)-'0') * num + c;
        c = n/10;
        s += '0' + n%10;
    }
    if (c != 0)
    {
        while (c != 0)
        {
            s += '0' + (c%10);
            c /= 10;
        }
    }

    *ps = "";
    for (string::size_type i = 0; i < s.size(); i++)
    {
        *ps += s[s.size()-i-1];
    }
}

int
main(int argc, char **argv)
{
    string s = "1";
    int  ans = 0;

    for (int i = 2; i <= NUM ; i++)
    {
        multi(&s, i);
    }

    for (string::iterator it = s.begin(), end = s.end(); it != end; it++)
    {
        ans += *it - '0';
    }

    cout << ans << endl;

    return 0;
}