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ラーニングレベルアップ問題集の「文字列の配列の入力」をやってみた。

Posted at

paizaラーニングレベルアップ問題集の「文字列の配列の入力」をやってみました。


問題
STEP: 1

STEP: 2

STEP: 3


C
STEP: 1
#include <stdio.h>

const char *S[] = { "eight", "one", "three", "paiza", "pa13", "813" };

int main() {
	int n = (int) (sizeof(S) / sizeof(S[0]));
	for (int i = 0; i < n; i++) puts(S[i]);
	return 0;
}
STEP: 2
#include <stdio.h>

const int N = 10;

int main() {
	char S[N][11];
	for (int i = 0; i < N; i++) scanf("%s", S[i]);
	for (int i = 0; i < N; i++) puts(S[i]);
	return 0;
}
STEP: 3
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	char S[n][11];
	for (int i = 0; i < n; i++) scanf("%s", S[i]);
	for (int i = 0; i < n; i++) puts(S[i]);
	return 0;
}
C++
STEP: 1
#include <iostream>
#include <vector>
using namespace std;

const vector<string> S = { "eight", "one", "three", "paiza", "pa13", "813" };

int main() {
	for (string s : S) cout << s << endl;
	return 0;
}
STEP: 2
#include <iostream>
#include <vector>
using namespace std;

int main() {
	vector<string> S;
	string s;
	cin >> s;
	while (!cin.fail()) {
		S.push_back(s);
		cin >> s;
	}
	for (string t : S) cout << t << endl;
	return 0;
}
STEP: 3
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> S(n);
	for (int i = 0; i < n; i++) cin >> S[i];
	for (string s : S) cout << s << endl;
	return 0;
}

C#
STEP: 1
using System;

class Program
{
	static readonly string[] S = { "eight", "one", "three", "paiza", "pa13", "813" };

	public static void Main()
	{
		foreach (string s in S) Console.WriteLine(s);
	}
}
STEP: 2
using System;

class Program
{
	public static void Main()
	{
		string[] S = Console.ReadLine().Split();
		foreach (string s in S) Console.WriteLine(s);
	}
}
STEP: 3
using System;

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

Go
STEP: 1
package main
import "fmt"

var S = []string{ "eight", "one", "three", "paiza", "pa13", "813" }

func main() {
	for _, s := range(S) {
		fmt.Println(s)
	}
}
STEP: 2
package main
import "fmt"

func main() {
	S := make([]string, 0)
	var s string
	for _, err := fmt.Scan(&s); err == nil; _, err = fmt.Scan(&s) {
		S = append(S, s)
	}
	for _, t := range(S) {
		fmt.Println(t)
	}
}
STEP: 3
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	S := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&S[i])
	}
	for _, s := range(S) {
		fmt.Println(s)
	}
}

Java
STEP: 1
public class Main {

	private static final String[] S = { "eight", "one", "three", "paiza", "pa13", "813" };
	
	public static void main(String[] args) {
		for (String s : S) System.out.println(s);
	}
}
STEP: 2
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] S = sc.nextLine().split(" ");
		sc.close();
		for (String s : S) System.out.println(s);
	}
}
STEP: 3
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		String[] S = sc.nextLine().split(" ");
		sc.close();
		for (int i = 0; i < n; i++) System.out.println(S[i]);
	}
}

JavaScript
STEP: 1
const S = ["eight", "one", "three", "paiza", "pa13", "813"];
S.forEach(s => console.log(s));
STEP: 2
const S = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ');
S.forEach(s => console.log(s));
STEP: 3
const [_, S] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(s => s.split(' '));
S.forEach(s => console.log(s));

Kotlin
STEP: 1
fun main() {
	val S = arrayOf("eight", "one", "three", "paiza", "pa13", "813")
	for (s in S) println(s)
}
STEP: 2
fun main() {
	val S = readLine()!!.split(' ')
	for (s in S) println(s)
}
STEP: 3
fun main() {
	val n = readLine()!!.toInt()
	val S = readLine()!!.split(' ')
	for (i in 0 until n) println(S[i])
}

PHP
STEP: 1
<?php
	$S = ["eight", "one", "three", "paiza", "pa13", "813"];
	foreach ($S as $s) echo $s, PHP_EOL;
?>
STEP: 2
<?php
	$S = explode(' ', trim(fgets(STDIN)));
	foreach ($S as $s) echo $s, PHP_EOL;
?>
STEP: 3
<?php
	$n = intval(fgets(STDIN));
	$S = explode(' ', trim(fgets(STDIN)));
	for ($i = 0; $i < $n; $i++) echo $S[$i], PHP_EOL;
?>

Perl
STEP: 1
my @S = ("eight", "one", "three", "paiza", "pa13", "813");
foreach (@S) {
	print "$_$/";
}
STEP: 2
my @S = split ' ', <STDIN>;
foreach (@S) {
	print "$_$/";
}
STEP: 3
my $n = int(<STDIN>);
my @S = split ' ', <STDIN>;
for (my $i = 0; $i < $n; $i++) {
	print "$S[$i]$/";
}

Python3
STEP: 1
S = ["eight", "one", "three", "paiza", "pa13", "813"]
for s in S:
	print(s)
STEP: 2
S = input().split()
for s in S:
	print(s)
STEP: 3
n = int(input())
S = input().split()
for i in range(n):
	print(S[i])

Ruby
STEP: 1
S = ["eight", "one", "three", "paiza", "pa13", "813"]
S.each do |s|
	puts s
end
STEP: 2
S = gets.chomp.split
S.each do |s|
	puts s
end
STEP: 3
N = gets.to_i
S = gets.chomp.split
N.times do |i|
	puts S[i]
end

Scala
STEP: 1
object Main extends App{
	val S = Array("eight", "one", "three", "paiza", "pa13", "813")
	for (s <- S) println(s)
}
STEP: 2
import scala.io.StdIn._

object Main extends App{
	val S = readLine().split(' ')
	for (s <- S) println(s)
}
STEP: 3
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val S = readLine().split(' ')
	for (i <- 0 until n) println(S(i))
}

Swift
STEP: 1
let S = ["eight", "one", "three", "paiza", "pa13", "813"]
for s in S {
	print(s)
}
STEP: 2
let S = readLine()!.split(separator: " ")
for s in S {
	print(s)
}
STEP: 3
let n = Int(readLine()!)!
let S = readLine()!.split(separator: " ")
for i in 0..<n {
	print(S[i])
}
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?