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つのデータの入力をやってみました。


問題


方針

言語により異なります。


C
#include <stdio.h>

int main() {
	for (int i = 0; i < 3; i++) {
		char s[101];
		scanf("%s", s);
		printf("%s\n", s);
	}
	return 0;
}

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

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

C#
using System;

class Program
{
	public static void Main()
	{
		foreach (string s in Console.ReadLine().Split()) Console.WriteLine(s);
	}
}

Go
package main
import "fmt"

func main() {
	for i := 0; i < 3; i++ {
		var s string
		fmt.Scan(&s)
		fmt.Println(s)
	}
}

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.next());
		sc.close();
	}
}

JavaScript
require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ').forEach(function (s) { console.log(s) });

Kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	for (i in 0 until 3)
		println(sc.next())
	sc.close()
}

PHP
<?php
	foreach (explode(" ", trim(fgets(STDIN))) as $s)
		echo "$s\n";
?>

Perl
chomp(my $S = <STDIN>);
foreach my $s (split(" ", $S)) {
	print "$s\n";
}

Python3
for s in input().split():
	print(s)

Ruby
gets.split.each do |s|
	puts s
end

Scala
import scala.io.StdIn._

object Main extends App{
	readLine().split(" ").foreach(println)
}

Swift
for s in readLine()!.split(separator: " ") {
	print(s)
}
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?