0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニングレベルアップ問題集の【半角スペース区切りの入力】をやってみた。

0
Posted at

paizaラーニングレベルアップ問題集の【半角スペース区切りの入力】をやってみました。


問題
1つの入力

半角スペース区切りの2つの入力

半角スペース区切りの3つの入力

半角スペース区切りの10個の入力

半角スペース区切りの1,000個の入力


5問とも同じコードで正解してみます。


C
#include <stdio.h>

int main(void){
    char s[11];
    while (scanf("%s", s) == 1)
        puts(s);
    return 0;
}

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

int main(void){
    string s;
    while (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(){
    var s string
    for i, err := fmt.Scan(&s); err == nil && i == 1; i, err = 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 (String s : sc.nextLine().split(" "))
	        System.out.println(s);
        sc.close();
	}
}

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

Kotlin
fun main() {
    for (s in readLine()!!.split(" ")) println(s)
}

PHP
<?php
    foreach (explode(' ', trim(fgets(STDIN))) as $s)
        echo $s, PHP_EOL;
?>

Perl
for (split ' ', <STDIN>) {
    print "$_$/";
}

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

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

Scala
import scala.io.StdIn._

object Main extends App{
    for (s <- readLine().split(" ")) {
        println(s)
    }
}

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?