paizaラーニングレベルアップ問題集の【ループメニュー】をやってみた。(3)

paizaラーニングレベルアップ問題集の【ループメニュー】をやってみました。
- - -
##### 問題
###### 数列の反転
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_reverse
###### 九九の表示1
https://paiza.jp/works/mondai/loop_problems/loop_problems__kuku_step1
###### 九九の表示2
https://paiza.jp/works/mondai/loop_problems/loop_problems__kuku_step2
###### 2の累乗を表示
https://paiza.jp/works/mondai/loop_problems/loop_problems__pow2
###### FizzBuzz
https://paiza.jp/works/mondai/loop_problems/loop_problems__fizzbuzz
- - -
- 今回は`reverse`関数等を封印します
- `for (int i = 0; i < N; i++)`の`i++`の部分を変えることによって実装してみました（ら、`if`文を使わないFizzBuzzが出来ました）
- - -
##### C
###### 数列の反転
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int A[n];
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	for (int i = n - 1; i >= 0; i--) printf("%d\n", A[i]);
	return 0;
}
```
###### 九九の表示1
```c
#include <stdio.h>

int main() {
	int n = 8;
	int m = n * 9;
	for (int i = n; i <= m; i += n) {
		printf("%d", i);
		putchar(i < m ? ' ' : '\n');
	}
	return 0;
}
```
###### 九九の表示2
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int m = n * 9;
	for (int i = n; i <= m; i += n) {
		printf("%d", i);
		putchar(i < m ? ' ' : '\n');
	}
	return 0;
}
```
###### 2の累乗を表示
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 2; i <= (1 << n); i *= 2) printf("%d\n", i);
	return 0;
}
```
###### FizzBuzz
```c
#include <stdio.h>

const int N = 100;

int main() {
	char s[N + 1][9];
	for (int i = 1; i <= N; i++) sprintf(s[i], "%d", i);
	for (int i = 3; i <= N; i += 3) sprintf(s[i], "Fizz");
	for (int i = 5; i <= N; i += 5) sprintf(s[i], "Buzz");
	for (int i = 15; i <= N; i += 15) sprintf(s[i], "FizzBuzz");
	for (int i = 1; i <= N; i++) puts(s[i]);
	return 0;
}
```
- - -
##### C++
###### 数列の反転
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; i++) cin >> A[i];
	for (int i = n - 1; i >= 0; i--) cout << A[i] << endl;
	return 0;
}
```
###### 九九の表示1
```cpp
#include <iostream>
using namespace std;

int main() {
	int n = 8;
	int m = n * 9;
	for (int i = n; i <= m; i += m) {
		cout << i;
		if (i < m) cout << ' ';
		else cout << endl;
	}
	return 0;
}
```
###### 九九の表示2
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	int m = n * 9;
	for (int i = n; i <= m; i += m) {
		cout << i;
		if (i < m) cout << ' ';
		else cout << endl;
	}
	return 0;
}
```
###### 2の累乗を表示
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 2; i <= (1 << n); i *= 2) cout << i << endl;
	return 0;
}
```
###### FizzBuzz
```cpp
#include <iostream>
using namespace std;

const int N = 100;

int main() {
	string s[N + 1];
	for (int i = 1; i <= N; i++) s[i] = to_string(i);
	for (int i = 3; i <= N; i += 3) s[i] = "Fizz";
	for (int i = 5; i <= N; i += 5) s[i] = "Buzz";
	for (int i = 15; i <= N; i += 15) s[i] = "FizzBuzz";
	for (int i = 1; i <= N; i++) cout << s[i] << endl;
	return 0;
}
```
- - -
##### C#
###### 数列の反転
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		for (int i = n - 1; i >= 0; i--) Console.WriteLine(A[i]);
	}
}
```
###### 九九の表示1
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = 8;
		int m = n * 9;
		for (int i = n; i <= m; i += n)
			if (i < m) Console.Write("" + i + ' ');
			else Console.WriteLine(i);
	}
}
```
###### 九九の表示2
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		int m = n * 9;
		for (int i = n; i <= m; i += n)
			if (i < m) Console.Write("" + i + " ");
			else Console.WriteLine(i);
	}
}
```
###### 2の累乗を表示
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = 2; i <= (1 << n); i *= 2) Console.WriteLine(i);
	}
}
```
###### FizzBuzz
```cs
using System;

class Program
{
	const int N = 100;
	
	public static void Main()
	{
		string[] s = new string[N + 1];
		for (int i = 1; i <= N; i++) s[i] = i.ToString();
		for (int i = 3; i <= N; i += 3) s[i] = "Fizz";
		for (int i = 5; i <= N; i += 5) s[i] = "Buzz";
		for (int i = 15; i <= N; i += 15) s[i] = "FizzBuzz";
		for (int i = 1; i <= N; i++) Console.WriteLine(s[i]);
	}
}
```
- - -
##### Go
###### 数列の反転
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&A[i])
	}
	for i := n - 1; i >= 0; i-- {
		fmt.Println(A[i])
	}
}
```
###### 九九の表示1
```go
package main
import "fmt"

func main() {
	n := 8
	m := n * 9
	for i := n; i <= m; i += n {
		if i < m {
			fmt.Printf("%d ", i)
		} else {
			fmt.Println(i)
		}
	}
}
```
###### 九九の表示2
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	m := n * 9
	for i := n; i <= m; i += n {
		if i < m {
			fmt.Printf("%d ", i)
		} else {
			fmt.Println(i)
		}
	}
}
```
###### 2の累乗を表示
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 2; i <= (1 << n); i *= 2 {
		fmt.Println(i)
	}
}
```
###### FizzBuzz
```go
package main

import (
	"fmt"
	"strconv"
)

const N = 100

func main() {
	s := []string{}
	for i := 0; i <= N; i++ {
		s = append(s, strconv.Itoa(i))
	}
	for i := 3; i <= N; i += 3 {
		s[i] = "Fizz"
	}
	for i := 5; i <= N; i += 5 {
		s[i] = "Buzz"
	}
	for i := 15; i <= N; i += 15 {
		s[i] = "FizzBuzz"
	}
	for i := 1; i <= N; i++ {
		fmt.Println(s[i])
	}
}
```
- - -
##### Java
###### 数列の反転
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		for (int i = 0; i < n; i++) A[i] = sc.nextInt();
		sc.close();
		for (int i = n - 1; i >= 0; i--) System.out.println(A[i]);
	}
}
```
###### 九九の表示1
```java
public class Main {
	public static void main(String[] args) {
		int n = 8;
		int m = n * 9;
		for (int i = n; i <= m; i += n)
			if (i < m) System.out.print("" + i + ' ');
			else System.out.println(i);
	}
}
```
###### 九九の表示2
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		int m = n * 9;
		for (int i = n; i <= m; i += n)
			if (i < m) System.out.print("" + i + ' ');
			else System.out.println(i);
	}
}
```
###### 2の累乗を表示
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		for (int i = 2; i <= (1 << n); i *= 2) System.out.println(i);
	}
}
```
###### FizzBuzz
```java
public class Main {

	static final int N = 100;
	
	public static void main(String[] args) {
		String[] s = new String[N + 1];
		for (int i = 1; i <= N; i++) s[i] = String.valueOf(i);
		for (int i = 3; i <= N; i += 3) s[i] = "Fizz";
		for (int i = 5; i <= N; i += 5) s[i] = "Buzz";
		for (int i = 15; i <= N; i += 15) s[i] = "FizzBuzz";
		for (int i = 1; i <= N; i++) System.out.println(s[i]);
	}
}
```
- - -
##### JavaScript
###### 数列の反転
```js
const [N, A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map((s, i) => i ? s.split(' ').map(Number) : Number(s));
for (var i = N - 1; i >= 0; i--) console.log(A[i]);
```
###### 九九の表示1
```js
const n = 8;
const m = n * 9;
let s = "";
for (var i = n; i <= m; i += n) {
	s += i;
	if (i < m) s += " ";
	else console.log(s);
}
```
###### 九九の表示2
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
const m = n * 9;
let s = "";
for (var i = n; i <= m; i += n) {
	s += i;
	if (i < m) s += " ";
	else console.log(s);
}
```
###### 2の累乗を表示
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
for (var i = 2; i <= (1 << n); i *= 2) console.log(i);
```
###### FizzBuzz
```js
const N = 100;
let s = []
for (var i = 0; i <= N; i++) s.push(String(i));
for (var i = 3; i <= N; i += 3) s[i] = "Fizz";
for (var i = 5; i <= N; i += 5) s[i] = "Buzz";
for (var i = 15; i <= N; i += 15) s[i] = "FizzBuzz";
for (var i = 1; i <= N; i++) console.log(s[i]);
```
- - -
##### Kotlin
###### 数列の反転
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val A = readLine()!!.split(' ').map { it.toInt() }
	for (i in n - 1 downTo 0) println(A[i])
}
```
###### 九九の表示1
```kotlin
fun main() {
	val n = 8
	val m = n * 9
	for (i in n..m step n) {
		if (i < m) print("" + i + ' ')
		else println(i)
	}
}
```
###### 九九の表示2
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	val m = n * 9
	for (i in n..m step n) {
		if (i < m) print("" + i + ' ')
		else println(i)
	}
}
```
###### 2の累乗を表示
```kotlin
fun main() {
	val n = readLine()!!.toInt()
	var i = 2
	while (i <= (1 shl n)) {
		println(i)
		i *= 2
	}
}
```
###### FizzBuzz
```kotlin
fun main() {
	val N = 100
	val s = Array(N + 1){ "" }
	for (i in 1..N) s[i] = i.toString()
	for (i in 3..N step 3) s[i] = "Fizz"
	for (i in 5..N step 5) s[i] = "Buzz"
	for (i in 15..N step 15) s[i] = "FizzBuzz"
	for (i in 1..N) println(s[i])
}
```
- - -
##### PHP
###### 数列の反転
```php
<?php
	$n = intval(fgets(STDIN));
	$A = array_map("intval", explode(' ', fgets(STDIN)));
	for ($i = $n - 1; $i >= 0; $i--) echo $A[$i], PHP_EOL;
?>
```
###### 九九の表示1
```php
<?php
	$n = 8;
	$m = $n * 9;
	for ($i = $n; $i <= $m; $i += $n) echo $i, $i < $m ? ' ' : PHP_EOL;
?>
```
###### 九九の表示2
```php
<?php
	$n = intval(fgets(STDIN));
	$m = $n * 9;
	for ($i = $n; $i <= $m; $i += $n) echo $i, $i < $m ? ' ' : PHP_EOL;
?>
```
###### 2の累乗を表示
```php
<?php
	$n = intval(fgets(STDIN));
	for ($i = 2; $i <= (1 << $n); $i *= 2) echo $i, PHP_EOL;
?>
```
###### FizzBuzz
```php
<?php
	const N = 100;
	$s = [];
	for ($i = 0; $i <= N; $i++) $s[] = strval($i);
	for ($i = 3; $i <= N; $i += 3) $s[$i] = "Fizz";
	for ($i = 5; $i <= N; $i += 5) $s[$i] = "Buzz";
	for ($i = 15; $i <= N; $i += 15) $s[$i] = "FizzBuzz";
	for ($i = 1; $i <= N; $i++) echo $s[$i], PHP_EOL;
?>
```
- - -
##### Perl
###### 数列の反転
```pl
my $n = int(<STDIN>);
my @A = map { int($_) } split ' ', <STDIN>;
for (my $i = $n - 1; $i >= 0; $i--) {
	print "$A[$i]$/";
}
```
###### 九九の表示1
```pl
my $n = 8;
my $m = $n * 9;
for (my $i = $n; $i <= $m; $i += $n) {
	print $i, $i < $m ? ' ' : $/;
}
```
###### 九九の表示2
```pl
my $n = int(<STDIN>);
my $m = $n * 9;
for (my $i = $n; $i <= $m; $i += $n) {
	print $i, $i < $m ? ' ' : $/;
}
```
###### 2の累乗を表示
```pl
my $n = int(<STDIN>);
for (my $i = 2; $i <= (1 << $n); $i *= 2) {
	print "$i$/";
}
```
###### FizzBuzz
```pl
my $N = 100;
my @s;
for (my $i = 0; $i <= $N; $i++) {
	push @s, "$i";
}
for (my $i = 3; $i <= $N; $i += 3) {
	$s[$i] = "Fizz";
}
for (my $i = 5; $i <= $N; $i += 5) {
	$s[$i] = "Buzz";
}
for (my $i = 15; $i <= $N; $i += 15) {
	$s[$i] = "FizzBuzz";
}
for (my $i = 1; $i <= $N; $i++) {
	print "$s[$i]$/";
}
```
- - -
##### Python3
###### 数列の反転
```py
n = int(input())
A = list(map(int, input().split()))
for i in range(n - 1, -1, -1):
	print(A[i])
```
###### 九九の表示1
```py
N = 8
M = N * 9
for i in range(N, M + 1, N):
	print(i, end=' ' if i < M else '\n')
```
###### 九九の表示2
```py
n = int(input())
m = n * 9
for i in range(n, m + 1, n):
	print(i, end=' ' if i < m else '\n')
```
###### 2の累乗を表示
```py
n = int(input())
i = 2
while i <= (1 << n):
	print(i)
	i *= 2
```
###### FizzBuzz
```py
N = 100
S = []
for i in range(N + 1):
	S.append(str(i))
for i in range(3, N + 1, 3):
	S[i] = "Fizz"
for i in range(5, N + 1, 5):
	S[i] = "Buzz"
for i in range(15, N + 1, 15):
	S[i] = "FizzBuzz"
for i in range(1, N + 1):
	print(S[i])
```
- - -
##### Ruby
###### 数列の反転
```rb
N = gets.to_i
A = gets.split.map(&:to_i)
(N-1).downto(0) do |i|
	p A[i]
end
```
###### 九九の表示1
```rb
N = 8
M = N * 9
(N..M).step(N) do |i|
	if i < M
		print i, ' '
	else
		p i
	end
end
```
###### 九九の表示2
```rb
N = gets.to_i
M = N * 9
(N..M).step(N) do |i|
	if i < M
		print i, ' '
	else
		p i
	end
end
```
###### 2の累乗を表示
```rb
N = gets.to_i
i = 2
while i <= (1 << N)
	p i
	i *= 2
end
```
###### FizzBuzz
```rb
N = 100
s = []
(0..N).each do |i|
	s << i.to_s
end
(3..N).step(3) do |i|
	s[i] = "Fizz"
end
(5..N).step(5) do |i|
	s[i] = "Buzz"
end
(15..N).step(15) do |i|
	s[i] = "FizzBuzz"
end
(1..N).each do |i|
	puts s[i]
end
```
- - -
##### Scala
###### 数列の反転
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val A = readLine().split(' ').map { _.toInt }
	for (i <- n-1 to 0 by -1) println(A(i))
}
```
###### 九九の表示1
```scala
object Main extends App{
	val n = 8
	val m = n * 9
	for (i <- n to m by n) {
		if (i < m) print("" + i + ' ')
		else println(i)
	}
}
```
###### 九九の表示2
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	val m = n * 9
	for (i <- n to m by n) {
		if (i < m) print("" + i + ' ')
		else println(i)
	}
}
```
###### 2の累乗を表示
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	var i = 2
	while (i <= (1 << n)) {
		println(i)
		i *= 2
	}
}
```
###### FizzBuzz
```scala
object Main extends App{
	val N = 100
	val s = new Array[String](N + 1)
	for (i <- 1 to N) s(i) = i.toString
	for (i <- 3 to N by 3) s(i) = "Fizz"
	for (i <- 5 to N by 5) s(i) = "Buzz"
	for (i <- 15 to N by 15) s(i) = "FizzBuzz"
	for (i <- 1 to N) println(s(i))
}
```
- - -
##### Swift
###### 数列の反転
```swift
let n = Int(readLine()!)!
let A = readLine()!.split(separator: " ").compactMap { Int($0) }
for i in stride(from: n - 1, through: 0, by: -1) {
	print(A[i])
}
```
###### 九九の表示1
```swift
let n = 8
let m = n * 9
for i in stride(from: n, through: m, by: n) {
	print(i, terminator: i < m ? " " : "\n")
}
```
###### 九九の表示2
```swift
let n = Int(readLine()!)!
let m = n * 9
for i in stride(from: n, through: m, by: n) {
	print(i, terminator: i < m ? " " : "\n")
}
```
###### 2の累乗を表示
```swift
let n = Int(readLine()!)!
var i = 2
while i <= (1 << n) {
	print(i)
	i *= 2
}
```
###### FizzBuzz
```swift
let N = 100
var s = Array<String>()
for i in 0...N {
	s.append(String(i))
}
for i in stride(from: 3, through: N, by: 3) {
	s[i] = "Fizz"
}
for i in stride(from: 5, through: N, by: 5) {
	s[i] = "Buzz"
}
for i in stride(from: 15, through: N, by: 15) {
	s[i] = "FizzBuzz"
}
for i in 1...N {
	print(s[i])
}
```