paizaラーニングレベルアップ問題集の【比較演算子】をやってみました。
問題
STEP: 1 比較演算子:==
STEP: 2 比較演算子:!=
STEP: 3 比較演算子:<
STEP: 4 比較演算子:<=
STEP: 5 式の比較
FINAL問題 文字列の比較
C
STEP: 1 比較演算子:==
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a == b);
return 0;
}
STEP: 2 比較演算子:!=
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a != b);
return 0;
}
STEP: 3 比較演算子:<
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a < b);
return 0;
}
STEP: 4 比較演算子:<=
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a <= b);
return 0;
}
STEP: 5 式の比較
#include <stdio.h>
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
printf("%d\n", a + b == c * d);
return 0;
}
FINAL問題 文字列の比較
#include <stdio.h>
#include <string.h>
int main() {
char s[21], t[21];
scanf("%s %s", s, t);
printf("%d\n", strcmp(s, t) == 0);
return 0;
}
C++
STEP: 1 比較演算子:==
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a == b) << endl;
return 0;
}
STEP: 2 比較演算子:!=
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a != b) << endl;
return 0;
}
STEP: 3 比較演算子:<
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a < b) << endl;
return 0;
}
STEP: 4 比較演算子:<=
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a <= b) << endl;
return 0;
}
STEP: 5 式の比較
#include <iostream>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << (a + b == c * d) << endl;
return 0;
}
FINAL問題 文字列の比較
#include <iostream>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
cout << (s == t) << endl;
return 0;
}
C#
STEP: 1 比較演算子:==
using System;
class Program
{
public static void Main()
{
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a == b);
}
}
STEP: 2 比較演算子:!=
using System;
class Program
{
public static void Main()
{
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a != b);
}
}
STEP: 3 比較演算子:<
using System;
class Program
{
public static void Main()
{
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a < b);
}
}
STEP: 4 比較演算子:<=
using System;
class Program
{
public static void Main()
{
int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = ab[0];
int b = ab[1];
Console.WriteLine(a <= b);
}
}
STEP: 5 式の比較
using System;
class Program
{
public static void Main()
{
int[] abcd = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
int a = abcd[0];
int b = abcd[1];
int c = abcd[2];
int d = abcd[3];
Console.WriteLine(a + b == c * d);
}
}
FINAL問題 文字列の比較
using System;
class Program
{
public static void Main()
{
string[] st = Console.ReadLine().Split();
string s = st[0];
string t = st[1];
Console.WriteLine(s.Equals(t));
}
}
Go
STEP: 1 比較演算子:==
package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
fmt.Println(a == b)
}
STEP: 2 比較演算子:!=
package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
fmt.Println(a != b)
}
STEP: 3 比較演算子:<
package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
fmt.Println(a < b)
}
STEP: 4 比較演算子:<=
package main
import "fmt"
func main() {
var a, b int
fmt.Scan(&a, &b)
fmt.Println(a <= b)
}
STEP: 5 式の比較
package main
import "fmt"
func main() {
var a, b, c, d int
fmt.Scan(&a, &b, &c, &d)
fmt.Println(a + b == c * d)
}
FINAL問題 文字列の比較
package main
import "fmt"
func main() {
var s, t string
fmt.Scan(&s, &t)
fmt.Println(s == t)
}
Java
STEP: 1 比較演算子:==
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.close();
}
}
STEP: 2 比較演算子:!=
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.close();
}
}
STEP: 3 比較演算子:<
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.close();
}
}
STEP: 4 比較演算子:<=
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.close();
}
}
STEP: 5 式の比較
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() * sc.nextInt());
sc.close();
}
}
FINAL問題 文字列の比較
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(sc.next().equals(sc.next()));
sc.close();
}
}
JavaScript
STEP: 1 比較演算子:==
const [a, b] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
console.log(a === b);
STEP: 2 比較演算子:!=
const [a, b] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
console.log(a !== b);
STEP: 3 比較演算子:<
const [a, b] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
console.log(a < b);
STEP: 4 比較演算子:<=
const [a, b] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
console.log(a <= b);
STEP: 5 式の比較
const [a, b, c, d] = require("fs").readFileSync("/dev/stdin", "utf8").split(' ').map(Number);
console.log(a + b === c * d);
FINAL問題 文字列の比較
const [s, t] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ');
console.log(s === t);
Kotlin
STEP: 1 比較演算子:==
fun main() {
val (a, b) = readLine()!!.split(' ').map { it.toInt() }
println(a == b)
}
STEP: 2 比較演算子:!=
fun main() {
val (a, b) = readLine()!!.split(' ').map { it.toInt() }
println(a != b)
}
STEP: 3 比較演算子:<
fun main() {
val (a, b) = readLine()!!.split(' ').map { it.toInt() }
println(a < b)
}
STEP: 4 比較演算子:<=
fun main() {
val (a, b) = readLine()!!.split(' ').map { it.toInt() }
println(a <= b)
}
STEP: 5 式の比較
fun main() {
val (a, b, c, d) = readLine()!!.split(' ').map { it.toInt() }
println(a + b == c * d)
}
FINAL問題 文字列の比較
fun main() {
val (s, t) = readLine()!!.split(' ')
println(s.equals(t))
}
PHP
STEP: 1 比較演算子:==
<?php
[$a, $b] = array_map("intval", explode(' ', fgets(STDIN)));
echo $a === $b ? 1 : 0, PHP_EOL;
?>
STEP: 2 比較演算子:!=
<?php
[$a, $b] = array_map("intval", explode(' ', fgets(STDIN)));
echo $a !== $b ? 1 : 0, PHP_EOL;
?>
STEP: 3 比較演算子:<
<?php
[$a, $b] = array_map("intval", explode(' ', fgets(STDIN)));
echo $a < $b ? 1 : 0, PHP_EOL;
?>
STEP: 4 比較演算子:<=
<?php
[$a, $b] = array_map("intval", explode(' ', fgets(STDIN)));
echo $a <= $b ? 1 : 0, PHP_EOL;
?>
STEP: 5 式の比較
<?php
[$a, $b, $c, $d] = array_map("intval", explode(' ', fgets(STDIN)));
echo $a + $b === $c * $d ? 1 : 0, PHP_EOL;
?>
FINAL問題 文字列の比較
<?php
[$s, $t] = explode(' ', trim(fgets(STDIN)));
echo $s === $t ? 1 : 0, PHP_EOL;
?>
Perl
STEP: 1 比較演算子:==
my ($a, $b) = map { int($_) } split ' ', <STDIN>;
print $a == $b ? 1 : 0, $/;
STEP: 2 比較演算子:!=
my ($a, $b) = map { int($_) } split ' ', <STDIN>;
print $a != $b ? 1 : 0, $/;
STEP: 3 比較演算子:<
my ($a, $b) = map { int($_) } split ' ', <STDIN>;
print $a < $b ? 1 : 0, $/;
STEP: 4 比較演算子:<=
my ($a, $b) = map { int($_) } split ' ', <STDIN>;
print $a <= $b ? 1 : 0, $/;
STEP: 5 式の比較
my ($a, $b, $c, $d) = map { int($_) } split ' ', <STDIN>;
print $a + $b == $c * $d ? 1 : 0, $/;
FINAL問題 文字列の比較
my ($s, $t) = split ' ', <STDIN>;
print $s eq $t ? 1 : 0, $/;
Python3
STEP: 1 比較演算子:==
a, b = map(int, input().split())
print(a == b)
STEP: 2 比較演算子:!=
a, b = map(int, input().split())
print(a != b)
STEP: 3 比較演算子:<
a, b = map(int, input().split())
print(a < b)
STEP: 4 比較演算子:<=
a, b = map(int, input().split())
print(a <= b)
STEP: 5 式の比較
a, b, c, d = map(int, input().split())
print(a + b == c * d)
FINAL問題 文字列の比較
s, t = input().split()
print(s == t)
Ruby
STEP: 1 比較演算子:==
a, b = gets.split.map(&:to_i)
p a == b
STEP: 2 比較演算子:!=
a, b = gets.split.map(&:to_i)
p a != b
STEP: 3 比較演算子:<
a, b = gets.split.map(&:to_i)
p a < b
STEP: 4 比較演算子:<=
a, b = gets.split.map(&:to_i)
p a <= b
STEP: 5 式の比較
a, b, c, d = gets.split.map(&:to_i)
p a + b == c * d
FINAL問題 文字列の比較
s, t = gets.split
p s == t
Scala
STEP: 1 比較演算子:==
import scala.io.StdIn._
object Main extends App{
val Array(a, b) = readLine().split(' ').map { _.toInt }
println(a == b)
}
STEP: 2 比較演算子:!=
import scala.io.StdIn._
object Main extends App{
val Array(a, b) = readLine().split(' ').map { _.toInt }
println(a != b)
}
STEP: 3 比較演算子:<
import scala.io.StdIn._
object Main extends App{
val Array(a, b) = readLine().split(' ').map { _.toInt }
println(a < b)
}
STEP: 4 比較演算子:<=
import scala.io.StdIn._
object Main extends App{
val Array(a, b) = readLine().split(' ').map { _.toInt }
println(a <= b)
}
STEP: 5 式の比較
import scala.io.StdIn._
object Main extends App{
val Array(a, b, c, d) = readLine().split(' ').map { _.toInt }
println(a + b == c * d)
}
FINAL問題 文字列の比較
import scala.io.StdIn._
object Main extends App{
val Array(s, t) = readLine().split(' ')
println(s.equals(t))
}
Swift
STEP: 1 比較演算子:==
let ab = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b) = (ab[0], ab[1])
print(a == b)
STEP: 2 比較演算子:!=
let ab = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b) = (ab[0], ab[1])
print(a != b)
STEP: 3 比較演算子:<
let ab = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b) = (ab[0], ab[1])
print(a < b)
STEP: 4 比較演算子:<=
let ab = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b) = (ab[0], ab[1])
print(a <= b)
STEP: 5 式の比較
let abcd = readLine()!.split(separator: " ").compactMap { Int($0) }
let (a, b, c, d) = (abcd[0], abcd[1], abcd[2], abcd[3])
print(a + b == c * d)
FINAL問題 文字列の比較
let st = readLine()!.split(separator: " ")
let (s, t) = (st[0], st[1])
print(s == t)