每天作死一道题——1、1骑士的金币(趣题学算法)

#include 
#include 

using namespace std;

int ask_coin (int);

int main ()
{
    int day;
    vector<int> vday;
    while (cin >> day){
        if (day==0)
           break;   
        vday.push_back(day);

    }
    for (auto days : vday)
        cout << days << " " << ask_coin(days) << endl;    
    //int coin = 0;
    //cout << endl 
    //     << "the number of coin = " 
    //     << coin;
    return 0; 
}

int ask_coin (int day)
{
    int a=0; //the day's conter
    int i;
    for (i=0; iif (a>day){
            a-=i;i--;
            break;
        }
    }
    //cout << a <<" "<< i;
    //the number of coin
    int coin=0;
    for (int j=1; j<=i; j++){
         coin+=j*j;  
    }
    coin+=(day-a)*(i+1);
    return coin;
}

你可能感兴趣的:(每天作死一道题)