paizaラーニングレベルアップ問題集の条件分岐の問題をやってみた。

paizaラーニングレベルアップ問題集の条件分岐の問題をやってみました。
- - -
##### 問題
###### 単純な条件分岐
https://paiza.jp/works/mondai/d_rank_level_up_problems/d_rank_level_up_problems__conditions_branch_1
###### 数値の分岐
https://paiza.jp/works/mondai/d_rank_level_up_problems/d_rank_level_up_problems__conditions_branch_2
###### 数値演算結果で分岐
https://paiza.jp/works/mondai/d_rank_level_up_problems/d_rank_level_up_problems__conditions_branch_3
###### 占い
https://paiza.jp/works/mondai/d_rank_level_up_problems/d_rank_level_up_problems__conditions_branch_boss
- - -
- `if`文を使ったコード
- 三項演算子を使ったコード

の2パターン掲載します（一部言語を除く）。
- - -
##### C
###### 単純な条件分岐
```c
#include <stdio.h>
#include <string.h>

int main() {
	char s[20];
	scanf("%s", s);
	if (strcmp(s, "paiza") == 0) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}
```
```c
#include <stdio.h>
#include <string.h>

int main() {
	char s[20];
	scanf("%s", s);
	puts(strcmp(s, "paiza") ? "NO" : "YES");
	return 0;
}
```
###### 数値の分岐
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	if (n <= 100) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}
```
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	puts(n <= 100 ? "YES" : "NO");
	return 0;
}
```
###### 数値演算結果で分岐
```c
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a * b <= c) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}
```
```c
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	puts(a * b <= c ? "YES" : "NO");
	return 0;
}
```
###### 占い
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	if (n == 7) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}
```
```c
#include <stdio.h>

int main() {
	puts(getchar() == '7' ? "Yes" : "No");
	return 0;
}
```
- - -
##### C++
###### 単純な条件分岐
```cpp
#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "paiza") {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
```
```cpp
#include <iostream>
using namespace std;

int main() {
	string s;
	cin >> s;
	cout << (s == "paiza" ? "YES" : "NO") << endl;
	return 0;
}
```
###### 数値の分岐
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n <= 100) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
```
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << (n <= 100 ? "YES" : "NO") << endl;
	return 0;
}
```
###### 数値演算結果で分岐
```cpp
#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a * b <= c) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
```
```cpp
#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a * b <= c ? "YES" : "NO") << endl;
	return 0;
}
```
###### 占い
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 7) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}
```
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << (n == 7 ? "Yes" : "No") << endl;
	return 0;
}
```
- - -
##### C#
###### 単純な条件分岐
```cs
using System;

class Program
{
	public static void Main()
	{
		string s = Console.ReadLine();
		if ("paiza".Equals(s)) {
			Console.WriteLine("YES");
		} else {
			Console.WriteLine("NO");
		}
	}
}
```
```cs
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine("paiza".Equals(Console.ReadLine()) ? "YES" : "NO");
	}
}
```
###### 数値の分岐
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		if (n <= 100) {
			Console.WriteLine("YES");
		} else {
			Console.WriteLine("NO");
		}
	}
}
```
```cs
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine(int.Parse(Console.ReadLine()) <= 100 ? "YES" : "NO");
	}
}
```
###### 数値演算結果で分岐
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int a = abc[0];
		int b = abc[1];
		int c = abc[2];
		if (a * b <= c) {
			Console.WriteLine("YES");
		} else {
			Console.WriteLine("NO");
		}
	}
}
```
```cs
using System;

class Program
{
	public static void Main()
	{
		int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int a = abc[0];
		int b = abc[1];
		int c = abc[2];
		Console.WriteLine(a * b <= c ? "YES" : "NO");
	}
}
```
###### 占い
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		if (n == 7) {
			Console.WriteLine("Yes");
		} else {
			Console.WriteLine("No");
		}
	}
}
```
```cs
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine("7".Equals(Console.ReadLine()) ? "Yes" : "No");
	}
}
```
- - -
##### Go
###### 単純な条件分岐
```go
package main
import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	if s == "paiza" {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
```
###### 数値の分岐
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	if n <= 100 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
```
###### 数値演算結果で分岐
```go
package main
import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if a * b <= c {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
```
###### 占い
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	if n == 7 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
```
- - -
##### Java
###### 単純な条件分岐
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		if ("paiza".equals(s)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
```
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("paiza".equals(sc.next()) ? "YES" : "NO");
		sc.close();
	}
}
```
###### 数値の分岐
```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();
		if (n <= 100) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
```
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc.nextInt() <= 100 ? "YES" : "NO");
		sc.close();
	}
}
```
###### 数値演算結果で分岐
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
		if (a * b <= c) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
```
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc.nextInt() * sc.nextInt() <= sc.nextInt() ? "YES" : "NO");
		sc.close();
	}
}
```
###### 占い
```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();
		if (n == 7) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}
```
```java
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		System.out.println(System.in.read() == '7' ? "Yes" : "No");
	}
}
```
- - -
##### JavaScript
###### 単純な条件分岐
```js
const s = require("fs").readFileSync("/dev/stdin", "utf8").trim();
if (s === "paiza") {
	console.log("YES");
} else {
	console.log("NO");
}
```
```js
console.log(require("fs").readFileSync("/dev/stdin", "utf8").trim() === "paiza" ? "YES" : "NO");
```
###### 数値の分岐
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
if (n <= 100) {
	console.log("YES");
} else {
	console.log("NO");
}
```
```js
console.log(require("fs").readFileSync("/dev/stdin", "utf8") <= 100 ? "YES" : "NO");
```
###### 数値演算結果で分岐
```js
const [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ').map(Number);
if (a * b <= c) {
	console.log("YES");
} else {
	console.log("NO");
}
```
```js
const [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ');
console.log(a * b <= c ? "YES" : "NO");
```
###### 占い
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
if (n === 7) {
	console.log("Yes");
} else {
	console.log("No");
}
```
```js
console.log(require("fs").readFileSync("/dev/stdin", "utf8") == 7 ? "Yes" : "No");
```
`"7" == 7`や`"7\n" == 7`は`true`になりますが、`"7" === 7`は`false`になります。
- - -
##### Kotlin
###### 単純な条件分岐
```kotlin
fun main() {
	val s = readLine()
	if ("paiza".equals(s)) {
		println("YES")
	} else {
		println("NO")
	}
}
```
```kotlin
fun main() {
	println(if ("paiza".equals(readLine())) "YES" else "NO")
}
```
###### 数値の分岐
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	val n = sc.nextInt()
	sc.close()
	if (n <= 100) {
		println("YES")
	} else {
		println("NO")
	}
}
```
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	println(if (sc.nextInt() <= 100) "YES" else "NO")
	sc.close()
}
```
###### 数値演算結果で分岐
```kotlin
fun main() {
	val (a, b, c) = readLine()!!.split(' ').map { it.toInt() }
	if (a * b <= c) {
		println("YES")
	} else {
		println("NO")
	}
}
```
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	println(if (sc.nextInt() * sc.nextInt() <= sc.nextInt()) "YES" else "NO")
	sc.close()
}
```
###### 占い
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	val n = sc.nextInt()
	sc.close()
	if (n == 7) {
		println("Yes")
	} else {
		println("No")
	}
}
```
```kotlin
import java.util.*

fun main() {
	println(if (System.`in`.read().toChar() == '7') "Yes" else "No")
}
```
- - -
##### PHP
###### 単純な条件分岐
```php
<?php
	$s = trim(fgets(STDIN));
	if ($s === "paiza") {
		echo "YES" . PHP_EOL;
	} else {
		echo "NO" . PHP_EOL;
	}
?>
```
```php
<?php
	echo trim(fgets(STDIN)) === "paiza" ? "YES" : "NO", PHP_EOL;
?>
```
###### 数値の分岐
```php
<?php
	$n = intval(fgets(STDIN));
	if ($n <= 100) {
		echo "YES" . PHP_EOL;
	} else {
		echo "NO" . PHP_EOL;
	}
?>
```
```php
<?php
	echo intval(fgets(STDIN)) <= 100 ? "YES" : "NO", PHP_EOL;
?>
```
###### 数値演算結果で分岐
```php
<?php
	[$a, $b, $c] = array_map('intval', explode(' ', fgets(STDIN)));
	if ($a * $b <= $c) {
		echo "YES" . PHP_EOL;
	} else {
		echo "NO" . PHP_EOL;
	}
?>
```
```php
<?php
	[$a, $b, $c] = explode(' ', fgets(STDIN));
	echo $a * $b <= $c ? "YES" : "NO", PHP_EOL;
?>
```
###### 占い
```php
<?php
	$n = intval(fgets(STDIN));
	if ($n === 7) {
		echo "Yes" . PHP_EOL;
	} else {
		echo "No" . PHP_EOL;
	}
?>
```
```php
<?php
	echo fgets(STDIN) == 7 ? "Yes" : "No", PHP_EOL;
?>
```
- - -
##### Perl
###### 単純な条件分岐
```pl
chomp(my $s = <STDIN>);
if ($s eq "paiza") {
	print "YES$/";
} else {
	print "NO$/";
}
```
```pl
chomp(my $s = <STDIN>);
print $s eq "paiza" ? "YES" : "NO", $/;
```
###### 数値の分岐
```pl
my $n = int(<STDIN>);
if ($n <= 100) {
	print "YES$/";
} else {
	print "NO$/";
}
```
```pl
print <STDIN> <= 100 ? "YES" : "NO", $/;
```
###### 数値演算結果で分岐
```pl
my ($a, $b, $c) = map { int($_) } split ' ', <STDIN>;
if ($a * $b <= $c) {
	print "YES$/";
} else {
	print "NO$/";
}
```
```pl
my ($a, $b, $c) = split ' ', <STDIN>;
print $a * $b <= $c ? "YES" : "NO", $/;
```
###### 占い
```pl
my $n = int(<STDIN>);
if ($n == 7) {
	print "Yes$/";
} else {
	print "No$/";
}
```
```pl
print <STDIN> == 7 ? "Yes" : "No", $/;
```
- - -
##### Python3
###### 単純な条件分岐
```py
s = input()
if s == "paiza":
	print("YES")
else:
	print("NO")
```
```py
print("YES" if input() == "paiza" else "NO")
```
###### 数値の分岐
```py
n = int(input())
if n <= 100:
	print("YES")
else:
	print("NO")
```
```py
print("YES" if int(input()) <= 100 else "NO")
```
###### 数値演算結果で分岐
```py
a, b, c = map(int, input().split())
if a * b <= c:
	print("YES")
else:
	print("NO")
```
```py
a, b, c = map(int, input().split())
print("YES" if a * b <= c else "NO")
```
###### 占い
```py
n = int(input())
if n == 7:
	print("Yes")
else:
	print("No")
```
```py
print("Yes" if input() == '7' else "NO")
```
- - -
##### Ruby
###### 単純な条件分岐
```rb
s = gets.chomp
if s == "paiza"
	puts "YES"
else
	puts "NO"
end
```
```rb
puts gets.chomp == "paiza" ? "YES" : "NO"
```
###### 数値の分岐
```rb
n = gets.to_i
if n <= 100
	puts "YES"
else
	puts "NO"
end
```
```rb
puts gets.to_i <= 100 ? "YES" : "NO"
```
###### 数値演算結果で分岐
```rb
a, b, c = gets.split.map(&:to_i)
if a * b <= c
	puts "YES"
else
	puts "NO"
end
```
```rb
a, b, c = gets.split.map(&:to_i)
puts a * b <= c ? "YES" : "NO"
```
###### 占い
```rb
n = gets.to_i
if n == 7
	puts "Yes"
else
	puts "No"
end
```
```rb
puts gets.chomp == '7' ? "Yes" : "No"
```
- - -
##### Scala
###### 単純な条件分岐
```scala
import scala.io.StdIn._

object Main extends App{
	val s = readLine()
	if ("paiza".equals(s)) {
		println("YES")
	} else {
		println("NO")
	}
}
```
```scala
import scala.io.StdIn._

object Main extends App{
	println(if ("paiza".equals(readLine())) "YES" else "NO")
}
```
###### 数値の分岐
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	if (n <= 100) {
		println("YES")
	} else {
		println("NO")
	}
}
```
```scala
import scala.io.StdIn._

object Main extends App{
	println(if (readInt() <= 100) "YES" else "NO")
}
```
###### 数値演算結果で分岐
```scala
import scala.io.StdIn._

object Main extends App{
	val Array(a, b, c) = readLine().split(" ").map(_.toInt)
	if (a * b <= c) {
		println("YES")
	} else {
		println("NO")
	}
}
```
```scala
import java.util._

object Main extends App{
	val sc = new Scanner(System.in)
	println(if (sc.nextInt() * sc.nextInt() <= sc.nextInt()) "YES" else "NO")
	sc.close()
}
```
###### 占い
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	if (n == 7) {
		println("Yes")
	} else {
		println("No")
	}
}
```
```scala
import java.util._

object Main extends App{
	println(if (System.in.read() == '7') "Yes" else "No")
}
```
- - -
##### Swift
###### 単純な条件分岐
```swift
let s = readLine()!
if (s == "paiza") {
	print("YES")
} else {
	print("NO")
}
```
```swift
print(readLine()! == "paiza" ? "YES" : "NO")
```
###### 数値の分岐
```swift
let n = Int(readLine()!)!
if (n <= 100) {
	print("YES")
} else {
	print("NO")
}
```
```swift
print(Int(readLine()!)! <= 100 ? "YES" : "NO")
```
###### 数値演算結果で分岐
```swift
let abc = readLine()!.split(separator: " ").map { Int($0)! }
let (a, b, c) = (abc[0], abc[1], abc[2])
if (a * b <= c) {
	print("YES")
} else {
	print("NO")
}
```
```swift
let abc = readLine()!.split(separator: " ").map { Int($0)! }
let (a, b, c) = (abc[0], abc[1], abc[2])
print(a * b <= c ? "YES" : "NO")
```
###### 占い
```swift
let n = Int(readLine()!)!
if (n == 7) {
	print("Yes")
} else {
	print("No")
}
```
```swift
print(readLine()! == "7" ? "Yes" : "No")
```