paizaラーニングレベルアップ問題集の「辞書順に出力」をやってみた。

paizaラーニングレベルアップ問題集の「辞書順に出力」をやってみました。
- - -
##### 問題
###### STEP: 1
https://paiza.jp/works/mondai/array_primer/array_primer__string_dictionary_step1
###### STEP: 2
https://paiza.jp/works/mondai/array_primer/array_primer__string_dictionary_step2
###### STEP: 3
https://paiza.jp/works/mondai/array_primer/array_primer__string_dictionary_step3
###### STEP: 4
https://paiza.jp/works/mondai/array_primer/array_primer__string_dictionary_boss
- - -
##### C
###### STEP: 1
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
	return strcmp((const char*) a, (const char*) b);
}

int main() {
	char S[][6] = {"zaipa", "izapa", "paiza"};
	int n = (int) (sizeof(S) / sizeof(S[0]));
	qsort(S, n, sizeof(S[0]), cmp);
	for (int i = 0; i < n; i++) puts(S[i]);
	return 0;
}
```
###### STEP: 2
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
	return strcmp((const char*) a, (const char*) b);
}

int main() {
	int n = 5;
	char S[n][11];
	for (int i = 0; i < n; i++) scanf("%s", S[i]);	
	qsort(S, n, sizeof(S[0]), cmp);
	for (int i = 0; i < n; i++) puts(S[i]);
	return 0;
}
```
###### STEP: 3
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
	return strcmp((const char*) a, (const char*) b);
}

int main() {
	int n;
	scanf("%d", &n);
	char S[n][11];
	for (int i = 0; i < n; i++) scanf("%s", S[i]);	
	qsort(S, n, sizeof(S[0]), cmp);
	for (int i = 0; i < n; i++) puts(S[i]);
	return 0;
}
```
###### STEP: 4
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmp(const void *a, const void *b) {
	return strcmp((const char*) a, (const char*) b);
}

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

int main() {
	vector<string> S = {"zaipa", "izapa", "paiza"};
	sort(S.begin(), S.end());
	for (string s : S) cout << s << endl;
	return 0;
}
```
###### STEP: 2
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

int main() {
	int n;
	cin >> n;
	vector<string> S(n);
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	for (int i = 0; i < n; i++) cout << S[i] << endl;
	return 0;
}
```
###### STEP: 4
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<string> S(n);
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	cout << S[k-1] << endl;
	return 0;
}
```
- - -
##### C#
###### STEP: 1
```cs
using System;

class Program
{
	public static void Main()
	{
		string[] S = {"zaipa", "izapa", "paiza"};
		Array.Sort(S);
		foreach (string s in S) Console.WriteLine(s);
	}
}
```
###### STEP: 2
```cs
using System;

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

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		string[] S = Console.ReadLine().Split();
		Array.Sort(S);
		for (int i = 0; i < n; i++) Console.WriteLine(S[i]);
	}
}
```
###### STEP: 4
```cs
using System;

class Program
{
	public static void Main()
	{
		int nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int k = nk[1];
		string[] S = Console.ReadLine().Split();
		Array.Sort(S);
		Console.WriteLine(S[k-1]);
	}
}
```
- - -
##### Go
###### STEP: 1
```go
package main
import (
	"fmt"
	"sort"
)

func main() {
	S := []string{"zaipa", "izapa", "paiza"}
	sort.Strings(S)
	for _, s := range(S) {
		fmt.Println(s)
	}
}
```
###### STEP: 2
```go
package main
import (
	"fmt"
	"sort"
)

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

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	S := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&S[i])
	}
	sort.Strings(S)
	fmt.Println(S[k-1])
}
```
- - -
##### Java
###### STEP: 1
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		String[] S = {"zaipa", "izapa", "paiza"};
		Arrays.sort(S);
		for (String s : S) System.out.println(s);
	}
}
```
###### STEP: 2
```java
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();
		Arrays.sort(S);
		for (String s : S) System.out.println(s);
	}
}
```
###### STEP: 3
```java
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();
		Arrays.sort(S);
		for (int i = 0; i < n; i++) System.out.println(S[i]);
	}
}
```
###### STEP: 4
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.nextLine();
		String[] S = sc.nextLine().split(" ");
		sc.close();
		Arrays.sort(S);
		System.out.println(S[k-1]);
	}
}
```
- - -
##### JavaScript
###### STEP: 1
```js
const S = ["zaipa", "izapa", "paiza"];
S.sort();
S.forEach(s => console.log(s));
```
###### STEP: 2
```js
const S = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ');
S.sort();
S.forEach(s => console.log(s));
```
###### STEP: 3
```js
const [n, S] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ') : Number(s));
S.sort();
for (var i = 0; i < n; i++) console.log(S[i]);
```
###### STEP: 4
```js
const [[n, k], S] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ') : s.split(' ').map(Number));
S.sort();
console.log(S[k-1]);
```
- - -
##### Kotlin
###### STEP: 1
```kotlin
fun main() {
	var S = arrayOf("zaipa", "izapa", "paiza")
	S.sort()
	for (s in S) println(s)
}
```
###### STEP: 2
```kotlin
fun main() {
	var S = readLine()!!.split(' ').toTypedArray()
	S.sort()
	for (s in S) println(s)
}
```
###### STEP: 3
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	var S = readLine()!!.split(' ').toTypedArray()
	S.sort()
	for (i in 0 until n) println(S[i])
}
```
###### STEP: 4
```kotlin
fun main() {
	val (_, k) = readLine()!!.split(' ').map { it.toInt() }
	var S = readLine()!!.split(' ').toTypedArray()
	S.sort()
	println(S[k-1])
}
```
- - -
##### PHP
###### STEP: 1
```php
<?php
	$S = ["zaipa", "izapa", "paiza"];
	sort($S);
	foreach ($S as $s) echo $s, PHP_EOL;
?>
```
###### STEP: 2
```php
<?php
	$S = explode(' ', trim(fgets(STDIN)));
	sort($S);
	foreach ($S as $s) echo $s, PHP_EOL;
?>
```
###### STEP: 3
```php
<?php
	$n = intval(fgets(STDIN));
	$S = explode(' ', trim(fgets(STDIN)));
	sort($S);
	for ($i = 0; $i < $n; $i++) echo $S[$i], PHP_EOL;
?>
```
###### STEP: 4
```php
<?php
	[$n, $k] = array_map("intval", explode(' ', fgets(STDIN)));
	$S = explode(' ', trim(fgets(STDIN)));
	sort($S);
	echo $S[$k-1], PHP_EOL;
?>
```
- - -
##### Perl
###### STEP: 1
```pl
my @S = ("zaipa", "izapa", "paiza");
my @T = sort @S;
foreach $t (@T) {
	print "$t$/";
}
```
###### STEP: 2
```pl
my @S = split ' ', <STDIN>;
my @T = sort @S;
foreach $t (@T) {
	print "$t$/";
}
```
###### STEP: 3
```pl
my $n = int(<STDIN>);
my @S = split ' ', <STDIN>;
my @T = sort @S;
for (my $i = 0; $i < $n; $i++) {
	print "$T[$i]$/";
}
```
###### STEP: 4
```pl
my ($n, $k) = map { int($_)} split ' ', <STDIN>;
my @S = split ' ', <STDIN>;
my @T = sort @S;
print "$T[$k-1]$/";
```
- - -
##### Python3
###### STEP: 1
```py
S = ["zaipa", "izapa", "paiza"]
S.sort()
for s in S:
	print(s)
```
###### STEP: 2
```py
S = input().split()
S.sort()
for s in S:
	print(s)
```
###### STEP: 3
```py
n = int(input())
S = input().split()
S.sort()
for i in range(n):
	print(S[i])
```
###### STEP: 4
```py
n, k = map(int, input().split())
S = input().split()
S.sort()
print(S[k-1])
```
- - -
##### Ruby
###### STEP: 1
```rb
S = ["zaipa", "izapa", "paiza"]
S.sort!()
S.each do |s|
	puts s
end
```
###### STEP: 2
```rb
S = gets.chomp.split
S.sort!()
S.each do |s|
	puts s
end
```
###### STEP: 3
```rb
n = gets.to_i
S = gets.chomp.split
S.sort!()
n.times do |i|
	puts S[i]
end
```
###### STEP: 4
```rb
n, k = gets.split.map(&:to_i)
S = gets.chomp.split
S.sort!()
puts S[k-1]
```
- - -
##### Scala
###### STEP: 1
```scala
import scala.io.StdIn._

object Main extends App{
	val S = Array("zaipa", "izapa", "paiza")
	val T = S.sorted
	for (t <- T) println(t)
}
```
###### STEP: 2
```scala
import scala.io.StdIn._

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

object Main extends App{
	val n = readLine().toInt
	val S = readLine().split(' ')
	val T = S.sorted
	for (i <- 0 until n) println(T(i))
}
```
###### STEP: 4
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(n, k) = readLine().split(' ').map { _.toInt }
	val S = readLine().split(' ')
	val T = S.sorted
	println(T(k-1))
}
```
- - -
##### Swift
###### STEP: 1
```swift
var S = ["zaipa", "izapa", "paiza"]
S.sort()
for s in S {
	print(s)
}
```
###### STEP: 2
```swift
var S = readLine()!.split(separator: " ")
S.sort()
for s in S {
	print(s)
}
```
###### STEP: 3
```swift
let n = Int(readLine()!)!
var S = readLine()!.split(separator: " ")
S.sort()
for i in 0..<n {
	print(S[i])
}
```
###### STEP: 4
```swift
let nk = readLine()!.split(separator: " ").compactMap { Int($0) }
let k = nk[1]
var S = readLine()!.split(separator: " ")
S.sort()
print(S[k-1])
```