Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
362211 | 涂浩然就是个神经 | 金币 | C++ | 通过 | 100 | 0 MS | 280 KB | 1532 | 2025-01-28 16:01:43 |
# include <iostream> //# include <String> using namespace std; int main(){ // 1. To get the last day that the knight spend int iDay=0; string inputDay=""; //cout << "please input the day:" << endl; getline(cin,inputDay); //cout << "You have put the number of day:" << inputDay << endl; iDay=stoi(inputDay); // 2. To determine the number of change gold coin int iChange=0; int iLeft=0; int iSum=0; while(true){ //cout << "The change time 'ichange' is:" << iChange << endl; //cout << "The sum of the day 'iSum' before while loop is:" << iSum << endl; //cout << "The day of left 'iLeft' is:" << iLeft << endl << endl; iSum=iSum+(iChange+1); if(iSum<iDay){ iChange=iChange+1; continue; }else if(iSum==iDay){ iChange=iChange+1; break; }else{ iLeft=iDay-(iSum-iChange-1); break; } } //cout << "The final change time 'iChange' is:" << iChange << endl; //cout << "The final sum of the day 'iSum' before while loop is:" << iSum << endl; //cout << "The final day of left 'iLeft' is:" << iLeft << endl << endl; // 3. To calculate the sum of gold coin int gSum=0; for(int i=0;i<=iChange;i++){ gSum=gSum+(i*i); //cout << "The change times are:" << i << endl; //cout << "The temporary sum of gold are:" << gSum << endl << endl; } gSum=gSum+(iChange+1)*iLeft; //cout << "The final sum of gold are:" << gSum; cout << gSum; return 0; }