# String# Input/Output

c717 - You can say that again!

🔗 前往 ZeroJudge 原題

題目描述

題目要求讀取一行字串,並將該字串輸出兩次,中間用空格分隔。

解題思路

此題為簡單的輸入輸出題。程式讀取一行字串,然後直接將該字串輸出兩次,中間用空格分隔即可。使用 getline 函數可以讀取包含空格的整行字串。ios::sync_with_stdio(false)cin.tie(NULL) 可以優化輸入輸出效率。

複雜度分析

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

程式碼

#include <iostream>
#include <string>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	string a;
	while(getline(cin,a)){
		cout << a << " " << a << endl;
	}
}

Discussion