题解 | #尼科彻斯定理#
尼科彻斯定理
http://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
int i, n; cin >> i; n = i;
int data = 1; string s,str;
if (i <= 1) cout << i;
if (i > 1)
{
do
{
data = data + (i - 1) * 2; //data是第i行第一个数,等于
i--;
} while (i > 0);
for (int j = 0; j < n; j++)
{
//int转为str
stringstream ss;
ss<<data;
ss>>s; str.append(s); str.push_back('+');
ss.clear(); //每搁一次转化之间一定要clear,不然会错
// cout << data << '+'; //直接int输出的话多一个'+',我不知带怎么去掉它,懒得想了直接stringstream转成string去掉最后一个'+'
data += 2;
}
str.pop_back(); //去掉最后多余的'+'
cout<<str;
}
return 0;
}