#include <stdio.h>
int main() {
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>
using namespace std;
int main() {
int ntests;
string name;
cin >> ntests;
for (int i = 0; i < ntests; i++) {
cin >> name;
cout << "Hello " << name << "!" << endl;
}
}
下面是Java的解:
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int nTests = scanner.nextInt();
for (int i = 0; i < nTests; i++) {
String name = scanner.next();
System.out.println("Hello " + name + "!");
}
}
}
下面是Python的解:
import sys
n = int(input())
for i in range(n):
name = sys.stdin.readline().rstrip('\n')
print('Hello %s!' % (name))
下面是C#的解:
using System;
public class Hello
{
public static void Main(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.
最后是Haskell的解:
import Prelude
main :: IO ()
main = do input <- getContents
putStr.unlines.map (\x -> "Hello " ++ x ++ "!").tail.lines $ input