結果如下:
程式碼如下:
結果如下:
程式碼如下:
#includeusing namespace std;
int main(){unsigned long long f[30001] = {0}, g[30001] = {0};f[1] = 1;g[1] = 1;unsigned input, check = 2;while ((cin >> input) && !cin.eof()){if (!(f[input] != 0 && g[input] != 0)){for (unsigned i = check; i <= input; i++){f[i] = i + f[i-1];g[i] = f[i] + g[i-1];}check = input;}cout << f[input] << " " << g[input] << "\n";}}搞不懂是什麼問題,導致輸出結果比系統要求的少一行?
已解決,將!cin.eof()拿掉