paizaラーニングレベルアップ問題集の【条件分岐メニュー】をやってみました。
問題
単純な条件分岐
数値の分岐
数値演算結果で分岐
ゼロ以外
0が含まれていないか判定
方針
- 最初の3問はコチラと同じです
- 
if文を使ったコードと三項演算子を使ったコードを掲載します
- 最終問題は$0$が入力された時点でNOを出力してプログラムを終了する方法もありますが、一応、入力は全て読み込みたいと思います- が、読者諸賢におかれましては、本当に「全て読み込」まれているか、ご確認いただきたいと思います。例えば
の様なコードでは、変数ans = ans && (int(input()) != 0)ansが既に偽の場合、int(input())の評価はされません。即ち、入力が読み込まれません
 
- が、読者諸賢におかれましては、本当に「全て読み込」まれているか、ご確認いただきたいと思います。例えば
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;
}
#include <stdio.h>
#include <string.h>
int main() {
	char s[20];
	scanf("%s", s);
	puts(strcmp(s, "paiza") ? "NO" : "YES");
	return 0;
}
数値の分岐
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	if (n <= 100) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	puts(n <= 100 ? "YES" : "NO");
	return 0;
}
数値演算結果で分岐
#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;
}
#include <stdio.h>
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	puts(a * b <= c ? "YES" : "NO");
	return 0;
}
ゼロ以外
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	if (n) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	puts(n ? "YES" : "NO");
	return 0;
}
0が含まれていないか判定
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	char* ans = "YES";
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if (!a) ans = "NO";
	}
	puts(ans);
	return 0;
}
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	int ans = 1;
	while (n--) {
		int a;
		scanf("%d", &a);
		ans = ans && a;
	}
	puts(ans ? "YES" : "NO");
	return 0;
}
C++
単純な条件分岐
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s == "paiza") {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	cout << (s == "paiza" ? "YES" : "NO") << endl;
	return 0;
}
数値の分岐
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n <= 100) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	cout << (n <= 100 ? "YES" : "NO") << endl;
	return 0;
}
数値演算結果で分岐
#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;
}
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a * b <= c ? "YES" : "NO") << endl;
	return 0;
}
ゼロ以外
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	cout << (n ? "YES" : "NO") << endl;
	return 0;
}
0が含まれていないか判定
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	string ans = "YES";
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (!a) ans = "NO";
	}
	cout << ans << endl;
	return 0;
}
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	bool ans = true;
	while (n--) {
		int a;
		cin >> a;
		ans = ans && a;
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}
C#
単純な条件分岐
using System;
class Program
{
	public static void Main()
	{
		string s = Console.ReadLine();
		if ("paiza".Equals(s)) {
			Console.WriteLine("YES");
		} else {
			Console.WriteLine("NO");
		}
	}
}
using System;
class Program
{
	public static void Main()
	{
		Console.WriteLine("paiza".Equals(Console.ReadLine()) ? "YES" : "NO");
	}
}
数値の分岐
using System;
class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		if (n <= 100) {
			Console.WriteLine("YES");
		} else {
			Console.WriteLine("NO");
		}
	}
}
using System;
class Program
{
	public static void Main()
	{
		Console.WriteLine(int.Parse(Console.ReadLine()) <= 100 ? "YES" : "NO");
	}
}
数値演算結果で分岐
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");
		}
	}
}
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");
	}
}
ゼロ以外
using System;
class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		if (n != 0) {
			Console.WriteLine("YES");
		} else {
			Console.WriteLine("NO");
		}
	}
}
using System;
class Program
{
	public static void Main()
	{
		Console.WriteLine(int.Parse(Console.ReadLine()) != 0 ? "YES" : "NO");
	}
}
0が含まれていないか判定
using System;
class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		string ans = "YES";
		for (int i = 0; i < n; i++) {
			int a = int.Parse(Console.ReadLine());
			if (a == 0) ans = "NO";
		}
		Console.WriteLine(ans);
	}
}
using System;
using System.Linq;
class Program
{
	static void Main()
	{
		Console.WriteLine(Enumerable.Range(0, int.Parse(Console.ReadLine())).Select(_ => int.Parse(Console.ReadLine())).ToArray().All(_ => _ != 0) ? "YES" : "NO");
	}
}
Go
単純な条件分岐
package main
import "fmt"
func main() {
	var s string
	fmt.Scan(&s)
	if s == "paiza" {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
数値の分岐
package main
import "fmt"
func main() {
	var n int
	fmt.Scan(&n)
	if n <= 100 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
数値演算結果で分岐
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")
	}
}
ゼロ以外
package main
import "fmt"
func main() {
	var n int
	fmt.Scan(&n)
	if n != 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}
0が含まれていないか判定
package main
import "fmt"
func main() {
	var n int
	fmt.Scan(&n)
	ans := "YES"
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a == 0 {
			ans = "NO"
		}
	}
	fmt.Println(ans)
}
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");
		}
	}
}
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();
	}
}
数値の分岐
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");
		}
	}
}
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();
	}
}
数値演算結果で分岐
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");
		}
	}
}
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();
	}
}
ゼロ以外
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 != 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc.nextInt() != 0 ? "YES" : "NO");
		sc.close();
	}
}
0が含まれていないか判定
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String ans = "YES";
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a == 0) {
				ans = "NO";
			}
		}
		sc.close();
		System.out.println(ans);
	}
}
import java.util.*;
import java.util.stream.IntStream;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(Arrays.stream(IntStream.range(0, sc.nextInt()).map(i -> sc.nextInt()).toArray()).noneMatch(i -> i == 0) ? "YES" : "NO");
		sc.close();
	}
}
JavaScript
単純な条件分岐
const s = require("fs").readFileSync("/dev/stdin", "utf8").trim();
if (s === "paiza") {
	console.log("YES");
} else {
	console.log("NO");
}
console.log(require("fs").readFileSync("/dev/stdin", "utf8").trim() === "paiza" ? "YES" : "NO");
数値の分岐
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
if (n <= 100) {
	console.log("YES");
} else {
	console.log("NO");
}
console.log(Number(require("fs").readFileSync("/dev/stdin", "utf8")) <= 100 ? "YES" : "NO");
数値演算結果で分岐
const [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
if (a * b <= c) {
	console.log("YES");
} else {
	console.log("NO");
}
const [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ');
console.log(a * b <= c ? "YES" : "NO");
ゼロ以外
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8"));
if (n) {
	console.log("YES");
} else {
	console.log("NO");
}
console.log(Number(require("fs").readFileSync("/dev/stdin", "utf8")) ? "YES" : "NO");
0が含まれていないか判定
const A = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(Number);
const n = A[0];
let ans = "YES";
for (var i = 1; i <= n; i++) {
	const a = A[i];
	if (!a) {
		ans = "NO";
	}
}
console.log(ans);
const [n, ...A] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n').map(Number);
console.log(A.every(a => a) ? "YES" : "NO");
Kotlin
単純な条件分岐
fun main() {
	val s = readLine()!!
	if ("paiza".equals(s)) {
		println("YES")
	} else {
		println("NO")
	}
}
fun main() {
	println(if ("paiza".equals(readLine()!!)) "YES" else "NO")
}
数値の分岐
fun main() {
	val n = readLine()!!.toInt()
	if (n <= 100) {
		println("YES")
	} else {
		println("NO")
	}
}
fun main() {
	println(if (readLine()!!.toInt() <= 100) "YES" else "NO")
}
数値演算結果で分岐
fun main() {
	val (a, b, c) = readLine()!!.split(' ').map { it.toInt() }
	if (a * b <= c) {
		println("YES")
	} else {
		println("NO")
	}
}
import java.util.*
fun main() {
	val sc = Scanner(System.`in`)
	println(if (sc.nextInt() * sc.nextInt() <= sc.nextInt()) "YES" else "NO")
	sc.close()
}
ゼロ以外
fun main() {
	val n = readLine()!!.toInt()
	if (n != 0) {
		println("YES")
	} else {
		println("NO")
	}
}
fun main() {
	println(if (readLine()!!.toInt() != 0) "YES" else "NO")
}
0が含まれていないか判定
fun main() {
	val n = readLine()!!.toInt()
	var ans = "YES"
	repeat (n) {
		val a = readLine()!!.toInt()
		if (a == 0) {
			ans = "NO"
		}
	}
	println(ans)
}
fun main() {
	println(if (Array(readLine()!!.toInt()) { readLine()!!.toInt() }.none { it == 0 }) "YES" else "NO")
}
PHP
単純な条件分岐
<?php
	$s = trim(fgets(STDIN));
	if ($s === "paiza") {
		echo "YES";
	} else {
		echo "NO";
	}
	echo PHP_EOL;
?>
<?php
	echo trim(fgets(STDIN)) === "paiza" ? "YES" : "NO", PHP_EOL;
?>
数値の分岐
<?php
	$n = intval(fgets(STDIN));
	if ($n <= 100) {
		echo "YES";
	} else {
		echo "NO";
	}
	echo PHP_EOL;
?>
<?php
	echo intval(fgets(STDIN)) <= 100 ? "YES" : "NO", PHP_EOL;
?>
数値演算結果で分岐
<?php
	[$a, $b, $c] = array_map("intval", explode(' ', trim(fgets(STDIN))));
	if ($a * $b <= $c) {
		echo "YES";
	} else {
		echo "NO";
	}
	echo PHP_EOL;
?>
<?php
	[$a, $b, $c] = array_map("intval", explode(' ', fgets(STDIN)));
	echo $a * $b <= $c ? "YES" : "NO", PHP_EOL;
?>
ゼロ以外
<?php
	$n = intval(fgets(STDIN));
	if ($n) {
		echo "YES";
	} else {
		echo "NO";
	}
	echo PHP_EOL;
?>
<?php
	echo intval(fgets(STDIN)) ? "YES" : "NO", PHP_EOL;
?>
0が含まれていないか判定
<?php
	$n = intval(fgets(STDIN));
	$ans = "YES";
	for ($i = 0; $i < $n; $i++) {
		$a = intval(fgets(STDIN));
		if (!$a) {
			$ans = "NO";
		}
	}
	echo "$ans\n";
?>
<?php
	$n = fgets(STDIN);
	$ans = true;
	while ($n--) {
		$ans = intval(fgets(STDIN)) && $ans;
	}
	echo $ans ? "YES" : "NO", PHP_EOL;
?>
Perl
単純な条件分岐
chomp(my $s = <STDIN>);
if ($s eq "paiza") {
	print "YES";
} else {
	print "NO";
}
print $/;
chomp(my $s = <STDIN>);
print $s eq "paiza" ? "YES" : "NO", $/;
数値の分岐
my $n = int(<STDIN>);
if ($n <= 100) {
	print "YES";
} else {
	print "NO";
}
print $/;
print int(<STDIN>) <= 100 ? "YES" : "NO", $/;
数値演算結果で分岐
my ($a, $b, $c) = map { int($_) } split ' ', <STDIN>;
if ($a * $b <= $c) {
	print "YES";
} else {
	print "NO";
}
print $/;
my ($a, $b, $c) = map { int($_) } split ' ', <STDIN>;
print $a * $b <= $c ? "YES" : "NO", $/;
ゼロ以外
my $n = int(<STDIN>);
if ($n) {
	print "YES";
} else {
	print "NO";
}
print $/;
print int(<STDIN>) ? "YES" : "NO", $/;
0が含まれていないか判定
my $n = int(<STDIN>);
my $ans = "YES";
for (my $i = 0; $i < $n; $i++) {
	my $a = int(<STDIN>);
	if (!$a) {
		$ans = "NO";
	}
}
print "$ans$/";
my ($n, @A) = map { int($_) } <STDIN>;
my $ans = 1;
for (my $i = 0; $i < $n; $i++) {
	$ans = $ans && $A[$i];
}
print $ans ? "YES" : "NO", $/;
Python3
単純な条件分岐
s = input()
if s == "paiza":
	print("YES")
else:
	print("NO")
print("YES" if input() == "paiza" else "NO")
数値の分岐
n = int(input())
if n <= 100:
	print("YES")
else:
	print("NO")
print("YES" if int(input()) <= 100 else "NO")
数値演算結果で分岐
a, b, c = map(int, input().split())
if a * b <= c:
	print("YES")
else:
	print("NO")
a, b, c = map(int, input().split())
print("YES" if a * b <= c else "NO")
ゼロ以外
n = int(input())
if n:
	print("YES")
else:
	print("NO")
print("YES" if int(input()) else "NO")
0が含まれていないか判定
n = int(input())
ans = "YES"
for _ in range(n):
	a = int(input())
	if not a:
		ans = "NO"
print(ans)
print("YES" if all([int(input()) for _ in range(int(input()))]) else "NO")
print("YES" if all([int(input()) for _ in range(int(input()))]) else "NO")
Ruby
単純な条件分岐
s = gets.chomp
if s == "paiza"
	puts "YES"
else
	puts "NO"
end
puts gets.chomp == "paiza" ? "YES" : "NO"
数値の分岐
n = gets.to_i
if n <= 100
	puts "YES"
else
	puts "NO"
end
puts gets.to_i <= 100 ? "YES" : "NO"
数値演算結果で分岐
a, b, c = gets.split.map(&:to_i)
if a * b <= c
	puts "YES"
else
	puts "NO"
end
a, b, c = gets.split.map(&:to_i)
puts a * b <= c ? "YES" : "NO"
ゼロ以外
n = gets.to_i
if n != 0
	puts "YES"
else
	puts "NO"
end
puts gets.to_i != 0 ? "YES" : "NO"
0が含まれていないか判定
n = gets.to_i
ans = "YES"
n.times do
	a = gets.to_i
	if a == 0
		ans = "NO"
	end
end
puts ans
puts Array.new(gets.to_i) { gets.to_i }.none? { |a| a == 0 } ? "YES" : "NO"
Scala
単純な条件分岐
import scala.io.StdIn._
object Main extends App{
	val s = readLine()
	if ("paiza".equals(s)) {
		println("YES")
	} else {
		println("NO")
	}
}
import scala.io.StdIn._
object Main extends App{
	println(if ("paiza".equals(readLine())) "YES" else "NO")
}
数値の分岐
import scala.io.StdIn._
object Main extends App{
	val n = readInt()
	if (n <= 100) {
		println("YES")
	} else {
		println("NO")
	}
}
import scala.io.StdIn._
object Main extends App{
	println(if (readInt() <= 100) "YES" else "NO")
}
数値演算結果で分岐
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")
	}
}
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()
}
ゼロ以外
import scala.io.StdIn._
object Main extends App{
	val n = readInt()
	if (n != 0) {
		println("YES")
	} else {
		println("NO")
	}
}
import scala.io.StdIn._
object Main extends App{
	println(if (readInt() != 0) "YES" else "NO")
}
0が含まれていないか判定
import scala.io.StdIn._
object Main extends App{
	val n = readInt()
	var ans = "YES"
	for (i <- 1 to n) {
		val a = readInt()
		if (a == 0) {
			ans = "NO"
		}
	}
	println(ans)
}
import scala.io.StdIn._
object Main extends App{
	println(if ((0 until readInt()).map(_ => readInt()).forall(_ != 0)) "YES" else "NO")
}
Swift
単純な条件分岐
let s = readLine()!
if s == "paiza" {
	print("YES")
} else {
	print("NO")
}
print(readLine()! == "paiza" ? "YES" : "NO")
数値の分岐
let n = Int(readLine()!)!
if n <= 100 {
	print("YES")
} else {
	print("NO")
}
print(Int(readLine()!)! <= 100 ? "YES" : "NO")
数値演算結果で分岐
let abc = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b, c) = (abc[0], abc[1], abc[2])
if a * b <= c {
	print("YES")
} else {
	print("NO")
}
let abc = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b, c) = (abc[0], abc[1], abc[2])
print(a * b <= c ? "YES" : "NO")
ゼロ以外
let n = Int(readLine()!)!
if n != 0 {
	print("YES")
} else {
	print("NO")
}
print(Int(readLine()!)! != 0 ? "YES" : "NO")
0が含まれていないか判定
let n = Int(readLine()!)!
var ans = "YES"
for _ in 0..<n {
	let a = Int(readLine()!)!
	if a == 0 {
		ans = "NO"
	}
}
print(ans)
let n = Int(readLine()!)!
var ans = true
for _ in 0..<n {
	ans = Int(readLine()!)! != 0 && ans
}
print(ans ? "YES" : "NO")