# String# Input/Output

c716 - Johnny B. Goode

🔗 前往 ZeroJudge 原題

題目描述

題目要求讀取一行字串,代表要加油的人的名字,然後輸出格式為 "Go, 人名, go go"。

解題思路

此題為簡單的字串輸入輸出題。程式只需要讀取一行字串,並按照題目要求的格式輸出即可。使用 getline 函數可以讀取包含空格的整行字串。std::ios::sync_with_stdio(false);std::cin.tie(0); 可以加速輸入輸出。

複雜度分析

  • 時間複雜度: O(n),其中 n 是輸入字串的長度。
  • 空間複雜度: O(n),用於儲存輸入字串。

程式碼

#include <iostream>
#include <string>

using namespace std;

int main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	string a;
	while(getline(cin,a)){
		cout << "Go, " << a << ", go go" << endl;
	}
	
}

Discussion