南阳理工 题目883 minecraft's cattles
原题:http://acm.nyist.net/JudgeOnline/problem.php?pid=883 AC:2014-01-18 12:12:59
这题本是水题,但我觉得题目不严谨,如果输入“9 1 299”时,答案有50多位数,本应用高精度做的,所以我也按高精度的要求AC该题。这题使用到①大数相加模板,②大数除2模板,③int变为string的方法。
做题中还发现南阳理工的OJ不支持64位整型的__int64写法,iostream不支持printf函数,会导致CE。
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
string MyAdd(string s1, string s2)
{
if (s2.size() > s1.size()) swap(s1, s2);
string::iterator p1 = s1.end(), p2 = s2.end();
while (p2 != s2.begin())
{
*p1 += *p2 - '0';
if (*p1 > '9') *p1 -= 10, *(p1-1) += 1;
p1--, p2--;
}
*p