# Simulation# Basic I/O

b970 - 我不說髒話 (續)

🔗 前往 ZeroJudge 原題

題目描述

題目要求根據輸入的整數 n,輸出 n 行字串 "I don't say swear words!",每行前面加上從 1 開始的流水編號。

解題思路

此題為簡單的模擬題。程式需要讀取一個整數 n,然後使用迴圈迭代 n 次,每次迭代輸出帶有編號的字串。迴圈變數 i 作為編號,與字串 "I don't say swear words!" 組合後輸出。

複雜度分析

  • 時間複雜度: O(n)
  • 空間複雜度: O(1)

程式碼

#include <iostream>

using namespace std;

int main(){
	
	int n=0;
	
	while(cin >> n){
		for(int i=1;i<=n;i++){
			cout << i << ". I don't say swear words!" <<endl;
		}
	}
	
	
}

Discussion