0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Qiita100万記事感謝祭!記事投稿キャンペーン開催のお知らせ

paizaラーニングレベルアップ問題集の「N行のデータの入力」をやってみた

Posted at

paizaラーニングレベルアップ問題集のN行のデータの入力をやってみました。


問題


方針

C
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		char s[102];
		printf("%s", fgets(s, sizeof(s), stdin));
	}
	return 0;
}

C++
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		getline(cin, s);
		cout << s << endl;
	}
	return 0;
}

C#
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = 0; i < n; i++) Console.WriteLine(Console.ReadLine());
	}
}

Go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scan(&n)

	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scanner.Scan()
		fmt.Println(scanner.Text())
	}
}

Java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine(); // 改行コードを読み捨てる。
		for (int i = 0; i < n; i++)
			System.out.println(sc.nextLine());
		sc.close();
	}
}

JavaScript
const lines = require("fs").readFileSync("/dev/stdin", "utf8").split('\n');
const n = Number(lines[0]);
for (var i = 1; i <= n; i++) console.log(lines[i]);

Kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	val n = sc.nextInt()
	sc.nextLine() // 改行コードを読み捨てる。
	repeat(n) {
		println(sc.nextLine())
	}
	sc.close()
}

PHP
<?php
	$n = intval(fgets(STDIN));
	for ($i = 0; $i < $n; $i++)
		echo trim(fgets(STDIN)) . PHP_EOL;
?>

Perl
chomp(my $n = <STDIN>);
for (my $i = 0; $i < $n; $i++) {
	chomp(my $s = <STDIN>);
	print "$s\n";
}

Python3
for _ in range(int(input())):
	print(input())

Ruby
gets.to_i.times do
	puts gets
end

Scala
import scala.io.StdIn._

object Main extends App{
	for (_ <- 1 to readInt()) println(readLine())
}

Swift
for _ in 1...Int(readLine()!)! {
	print(readLine()!)
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?