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

Posted at

paizaラーニングレベルアップ問題集の「$i$番目の出力」をやってみました。


問題
STEP: 1

STEP: 2

STEP: 3

STEP: 4


C
STEP: 1
#include <stdio.h>

const char *S[] = { "good", "morning", "paiza", "813", "pa13" };

int main() {
	int n;
	scanf("%d", &n);
	puts(S[n-1]);
	return 0;
}
STEP: 2
#include <stdio.h>

const int M = 5;

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

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	char s[m][11];
	for (int i = 0; i < m; i++) scanf("%s", s[i]);
	puts(s[n-1]);
	return 0;
}
STEP: 4
#include <stdio.h>

int main() {
	int n, m, l;
	scanf("%d %d %d", &n, &m, &l);
	char s[m][11];
	for (int i = 0; i < m; i++) scanf("%s", s[i]);
	putchar(s[n-1][l-1]);
	return 0;
}

C++
STEP: 1
#include <iostream>
#include <vector>
using namespace std;

const vector<string> S = { "good", "morning", "paiza", "813", "pa13" };

int main() {
	int n;
	cin >> n;
	cout << S[n-1] << endl;
	return 0;
}
STEP: 2
#include <iostream>
#include <vector>
using namespace std;

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<string> S(m);
	for (int i = 0; i < m; i++) cin >> S[i];
	cout << S[n-1] << endl;
	return 0;
}
STEP: 4
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n, m, l;
	cin >> n >> m >> l;
	vector<string> S(m);
	for (int i = 0; i < m; i++) cin >> S[i];
	cout << S[n-1][l-1] << endl;
	return 0;
}

C#
STEP: 1
using System;

class Program
{
	static readonly string[] S = { "good", "morning", "paiza", "813", "pa13" };
	
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		Console.WriteLine(S[n-1]);
	}
}
STEP: 2
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		string[] S = Console.ReadLine().Split();
		Console.WriteLine(S[n-1]);
	}
}
STEP: 3
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine().Split()[0]);
		string[] S = Console.ReadLine().Split();
		Console.WriteLine(S[n-1]);
	}
}
STEP: 4
using System;

class Program
{
	public static void Main()
	{
		int nml = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = nml[0], l = nml[2];
		string[] S = Console.ReadLine().Split();
		Console.WriteLine(S[n-1][l-1]);
	}
}

Go
STEP: 1
package main
import "fmt"

var S = []string{ "good", "morning", "paiza", "813", "pa13" }

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(S[n-1])
}
STEP: 2
package main
import "fmt"

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

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	S := make([]string, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&S[i])
	}
	fmt.Println(S[n-1])
}
STEP: 4
package main
import "fmt"

func main() {
	var n, m, l int
	fmt.Scan(&n, &m, &l)
	S := make([]string, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&S[i])
	}
	fmt.Printf("%c\n", S[n-1][l-1])
}

Java
STEP: 1
import java.util.*;

public class Main {

	static final String[] S = { "good", "morning", "paiza", "813", "pa13" };
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		System.out.println(S[n-1]);
	}
}
STEP: 2
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();
		System.out.println(S[n-1]);
	}
}
STEP: 3
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.nextLine();
		String[] S = sc.nextLine().split(" ");
		sc.close();
		System.out.println(S[n-1]);
	}
}
STEP: 4
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		sc.nextLine();
		String[] S = sc.nextLine().split(" ");
		sc.close();
		System.out.println(S[n-1].toCharArray()[l-1]);
	}
}

JavaScript
STEP: 1
const S = ["good", "morning", "paiza", "813", "pa13"];
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
console.log(S[n-1]);
STEP: 2
const [n, S] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ') : Number(s));
console.log(S[n-1]);
STEP: 3
const [[n, m], S] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ') : s.split(' ').map(Number));
console.log(S[n-1]);
STEP: 4
const [[n, m, l], S] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ') : s.split(' ').map(Number));
console.log(S[n-1][l-1]);

Kotlin
STEP: 1
fun main() {
	val S = arrayOf("good", "morning", "paiza", "813", "pa13")
	val n = readLine()!!.toInt()
	println(S[n-1])
}
STEP: 2
fun main() {
	val n = readLine()!!.toInt()
	val S = readLine()!!.split(' ')
	println(S[n-1])
}
STEP: 3
fun main() {
	val (n, _) = readLine()!!.split(' ').map { it.toInt() }
	val S = readLine()!!.split(' ')
	println(S[n-1])
}
STEP: 4
fun main() {
	val (n, _, l) = readLine()!!.split(' ').map { it.toInt() }
	val S = readLine()!!.split(' ')
	println(S[n-1][l-1])
}

PHP
STEP: 1
<?php
	$S = ["good", "morning", "paiza", "813", "pa13"];
	$n = intval(fgets(STDIN));
	echo $S[$n-1], PHP_EOL;
?>
STEP: 2
<?php
	$n = intval(fgets(STDIN));
	$S = explode(' ', trim(fgets(STDIN)));
	echo $S[$n-1], PHP_EOL;
?>
STEP: 3
<?php
	[$n, $m] = array_map("intval", explode(' ', fgets(STDIN)));
	$S = explode(' ', trim(fgets(STDIN)));
	echo $S[$n-1], PHP_EOL;
?>
STEP: 4
<?php
	[$n, $m, $l] = array_map("intval", explode(' ', fgets(STDIN)));
	$S = explode(' ', trim(fgets(STDIN)));
	echo $S[$n-1][$l-1], PHP_EOL;
?>

Perl
STEP: 1
my @S = ("good", "morning", "paiza", "813", "pa13");
my $n = int(<STDIN>);
print "$S[$n-1]$/";
STEP: 2
my $n = int(<STDIN>);
my @S = split ' ', <STDIN>;
print "$S[$n-1]$/";
STEP: 3
my ($n, $m) = map { int($_) } split ' ', <STDIN>;
my @S = split ' ', <STDIN>;
print "$S[$n-1]$/";
STEP: 4
my ($n, $m, $l) = map { int($_) } split ' ', <STDIN>;
my @S = split ' ', <STDIN>;
print substr($S[$n-1], $l-1, 1), $/;

Python3
STEP: 1
S = ["good", "morning", "paiza", "813", "pa13"]
n = int(input())
print(S[n-1])
STEP: 2
n = int(input())
S = input().split()
print(S[n-1])
STEP: 3
n, _ = map(int, input().split())
S = input().split()
print(S[n-1])
STEP: 4
n, _, l = map(int, input().split())
S = input().split()
print(S[n-1][l-1])

Ruby
STEP: 1
S = ["good", "morning", "paiza", "813", "pa13"]
n = gets.to_i
puts S[n-1]
STEP: 2
n = gets.to_i
S = gets.split
puts S[n-1]
STEP: 3
n, _ = gets.split.map(&:to_i)
S = gets.split
puts S[n-1]
STEP: 4
n, _, l = gets.split.map(&:to_i)
S = gets.split
puts S[n-1][l-1]

Scala
STEP: 1
import scala.io.StdIn._

object Main extends App{
	val S = Array("good", "morning", "paiza", "813", "pa13")
	val n = readInt()
	println(S(n-1))
}
STEP: 2
import scala.io.StdIn._

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

object Main extends App{
	val Array(n, m) = readLine().split(' ').map { _.toInt }
	val S = readLine().split(' ')
	println(S(n-1))
}
STEP: 4
import scala.io.StdIn._

object Main extends App{
	val Array(n, m, l) = readLine().split(' ').map { _.toInt }
	val S = readLine().split(' ')
	println(S(n-1)(l-1))
}

Swift
STEP: 1
let S = ["good", "morning", "paiza", "813", "pa13"]
let n = Int(readLine()!)!
print(S[n-1])
STEP: 2
let n = Int(readLine()!)!
let S = readLine()!.split(separator: " ")
print(S[n-1])
STEP: 3
let n = Int(readLine()!.split(separator: " ")[0])!
let S = readLine()!.split(separator: " ")
print(S[n-1])
STEP: 4
let nml = readLine()!.split(separator: " ").compactMap { Int($0) }
let (n, l) = (nml[0], nml[2])
let S = readLine()!.split(separator: " ")
let s = S[n-1]
print(s[s.index(s.startIndex, offsetBy: l-1)])
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?