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?

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

Posted at

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


問題


方針

1行のデータの入力を3回繰り返します。


C
#include <stdio.h>

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

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

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

C#
using System;

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

Go
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < 3; i++ {
		if 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);
		for (int i = 0; i < 3; i++)
			System.out.println(sc.nextLine());
		sc.close();
	}
}

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

Kotlin
fun main() {
	repeat(3) {
		println(readLine())
	}
}

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

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

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

Ruby
3.times do puts gets end

Scala
import scala.io.StdIn._

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

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

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?