而且还加入了大量的主题,直接或模板Java我们能够在水。
除了循环33它的时间,计算A99它是第几,输出准确回答。
#include <stdio.h>
#include <string>
#include <algorithm>
using std::string; const int MAX_B = 5120;
char buf[MAX_B];
int id = 0, len = 0; inline char getFromBuf()
{
if (id >= len)
{
len = fread(buf, 1, MAX_B, stdin);
id = 0;
}
return buf[id++];
} void getIntFromBuf(string &n)
{
char a = getFromBuf();
while ((a == ' ' || a == '\n') && len) a = getFromBuf(); n.clear();
while ((a != ' ' && a != '\n') && len)//老是写&&,错成||
{
n.push_back(a);
a = getFromBuf();
}
} string operator+(string &a, string &b)
{
string c;
int N1 = (int)a.size(), N2 = (int)b.size();
int carry = 0;
for (int i = N1-1, j = N2-1; i>=0 || j>=0 || carry; i--, j--)
{
int an = i>=0? a[i]-'0' : 0;
int bn = j>=0? b[j]-'0' : 0;
int sum = an + bn + carry;
carry = sum / 10;
c.push_back(sum % 10 + '0');
}
reverse(c.begin(), c.end());
return c;
} int main()
{
string a1, a2, a3;
while (true)
{
getIntFromBuf(a1);
if (len == 0) break;
getIntFromBuf(a2);
getIntFromBuf(a3); for (int i = 0; i < 33; i++)
{
string a = a2 + a3;
a1 = a1 + a;
if (i == 32) break;
a2 = a1 + a;
a3 = a3 + a1;
a3 = a3 + a2;
}
puts(a1.c_str());
}
return 0;
}
版权声明:笔者心脏靖,景空间地址:http://blog.csdn.net/kenden23/,可能不会在未经作者同意转载。