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ラーニングレベルアップ問題集の条件分岐の問題をやってみた。

Posted at

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


問題
単純な条件分岐

数値の分岐

数値演算結果で分岐

占い


  • if文を使ったコード
  • 三項演算子を使ったコード

の2パターン掲載します(一部言語を除く)。


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 == 7) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}
#include <stdio.h>

int main() {
	puts(getchar() == '7' ? "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 == 7) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << (n == 7 ? "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 == 7) {
			Console.WriteLine("Yes");
		} else {
			Console.WriteLine("No");
		}
	}
}
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine("7".Equals(Console.ReadLine()) ? "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 == 7 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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 == 7) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		System.out.println(System.in.read() == '7' ? "Yes" : "No");
	}
}

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(require("fs").readFileSync("/dev/stdin", "utf8") <= 100 ? "YES" : "NO");
数値演算結果で分岐
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");
}
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 === 7) {
	console.log("Yes");
} else {
	console.log("No");
}
console.log(require("fs").readFileSync("/dev/stdin", "utf8") == 7 ? "Yes" : "No");

"7" == 7"7\n" == 7trueになりますが、"7" === 7falseになります。


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")
}
数値の分岐
import java.util.*

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

fun main() {
	val sc = Scanner(System.`in`)
	println(if (sc.nextInt() <= 100) "YES" else "NO")
	sc.close()
}
数値演算結果で分岐
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()
}
占い
import java.util.*

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

fun main() {
	println(if (System.`in`.read().toChar() == '7') "Yes" else "No")
}

PHP
単純な条件分岐
<?php
	$s = trim(fgets(STDIN));
	if ($s === "paiza") {
		echo "YES" . PHP_EOL;
	} else {
		echo "NO" . PHP_EOL;
	}
?>
<?php
	echo trim(fgets(STDIN)) === "paiza" ? "YES" : "NO", PHP_EOL;
?>
数値の分岐
<?php
	$n = intval(fgets(STDIN));
	if ($n <= 100) {
		echo "YES" . PHP_EOL;
	} else {
		echo "NO" . PHP_EOL;
	}
?>
<?php
	echo intval(fgets(STDIN)) <= 100 ? "YES" : "NO", PHP_EOL;
?>
数値演算結果で分岐
<?php
	[$a, $b, $c] = array_map('intval', explode(' ', fgets(STDIN)));
	if ($a * $b <= $c) {
		echo "YES" . PHP_EOL;
	} else {
		echo "NO" . PHP_EOL;
	}
?>
<?php
	[$a, $b, $c] = explode(' ', fgets(STDIN));
	echo $a * $b <= $c ? "YES" : "NO", PHP_EOL;
?>
占い
<?php
	$n = intval(fgets(STDIN));
	if ($n === 7) {
		echo "Yes" . PHP_EOL;
	} else {
		echo "No" . PHP_EOL;
	}
?>
<?php
	echo fgets(STDIN) == 7 ? "Yes" : "No", PHP_EOL;
?>

Perl
単純な条件分岐
chomp(my $s = <STDIN>);
if ($s eq "paiza") {
	print "YES$/";
} else {
	print "NO$/";
}
chomp(my $s = <STDIN>);
print $s eq "paiza" ? "YES" : "NO", $/;
数値の分岐
my $n = int(<STDIN>);
if ($n <= 100) {
	print "YES$/";
} else {
	print "NO$/";
}
print <STDIN> <= 100 ? "YES" : "NO", $/;
数値演算結果で分岐
my ($a, $b, $c) = map { int($_) } split ' ', <STDIN>;
if ($a * $b <= $c) {
	print "YES$/";
} else {
	print "NO$/";
}
my ($a, $b, $c) = split ' ', <STDIN>;
print $a * $b <= $c ? "YES" : "NO", $/;
占い
my $n = int(<STDIN>);
if ($n == 7) {
	print "Yes$/";
} else {
	print "No$/";
}
print <STDIN> == 7 ? "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 == 7:
	print("Yes")
else:
	print("No")
print("Yes" if input() == '7' 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 == 7
	puts "Yes"
else
	puts "No"
end
puts gets.chomp == '7' ? "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 == 7) {
		println("Yes")
	} else {
		println("No")
	}
}
import java.util._

object Main extends App{
	println(if (System.in.read() == '7') "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: " ").map { 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: " ").map { Int($0)! }
let (a, b, c) = (abc[0], abc[1], abc[2])
print(a * b <= c ? "YES" : "NO")
占い
let n = Int(readLine()!)!
if (n == 7) {
	print("Yes")
} else {
	print("No")
}
print(readLine()! == "7" ? "Yes" : "No")
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?