ans input_string = input() print(f"hello, {input_string}") |
這是一個非常經典的練習題,適合初學者熟悉基本的輸入輸出操作。以下是幾種不同程式語言的範例程式碼: ### C++ ```cpp #include <iostream> #include <string> int main() { std::string input; std::getline(std::cin, input); std::cout << "hello, " << input << std::endl; return 0; } ``` ### Python ```python input_string = input() print(f"hello, {input_string}") ``` ### Java ```java import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); System.out.println("hello, " + input); } } ``` ### JavaScript (Node.js) ```javascript const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question('', (input) => { console.log(`hello, ${input}`); rl.close(); }); ``` ### C# ```csharp using System; class Program { static void Main() { string input = Console.ReadLine(); Console.WriteLine("hello, " + input); } } ``` ### Go ```go package main import ( "bufio" "fmt" "os" ) func main() { reader := bufio.NewReader(os.Stdin) input, _ := reader.ReadString('\n') fmt.Printf("hello, %s", input) } ``` 這些範例程式碼都能夠讀取一行輸入並輸出指定格式的字串。你可以選擇你熟悉的程式語言來練習這個題目。希望這些範例對你有幫助!如果有其他問題,隨時告訴我。 |