# String# Input/Output

f700 - 劃重點

🔗 前往 ZeroJudge 原題

題目描述

題目要求讀取一行字串,並在該字串下方輸出相同長度的波浪線。

解題思路

此題為簡單的字串處理題目。主要步驟如下:

  1. 讀取一行字串。
  2. 輸出讀取的字串。
  3. 輸出與字串長度相同的波浪線字元 '~'。

複雜度分析

  • 時間複雜度: O(n),其中 n 是輸入字串的長度。這是因為需要遍歷字串一次來輸出波浪線。
  • 空間複雜度: O(1),因為只使用了常數額外的空間。

程式碼

#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    getline(cin,s);
    cout << s << "\n";
    for(int i=0;i<s.size();++i){
    	cout << '~';
	}
}

Discussion