#include<stdio.h>intmain() {int i, ntests;char name[100];scanf("%d\n",&ntests);for (i =0; i < ntests; i++) {scanf("%s\n", name);printf("Hello %s!\n", name); }}
下面是C++的解:
#include<iostream>#include<string>usingnamespace std;intmain() {int ntests; string name; cin >> ntests;for (int i =0; i < ntests; i++) { cin >> name; cout <<"Hello "<< name <<"!"<< endl; }}
下面是Java的解:
importjava.util.*;classMain {publicstaticvoidmain(String[] args) {Scanner scanner =newScanner(System.in);int nTests =scanner.nextInt();for (int i =0; i < nTests; i++) {String name =scanner.next();System.out.println("Hello "+ name +"!"); } }}
下面是Python的解:
import sysn =int(input())for i inrange(n): name = sys.stdin.readline().rstrip('\n')print('Hello %s!'% (name))
下面是C#的解:
usingSystem;publicclassHello{publicstaticvoidMain(string[] args) {int nTests =int.Parse(Console.ReadLine());for (int i =0; i < nTests; i++) {string name =Console.ReadLine();Console.WriteLine("Hello "+name+"!"); } }}
下面是Pascal的解:
program example(input, output);
var
ntests, test : integer;
name : string[100];
begin
readln(ntests);
for test := 1 to ntests do
begin
readln(name);
writeln('Hello ', name, '!');
end;
end.