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ラーニングレベルアップ問題集の乗客人数をやってみました。


問題


方針1

ある電車に$a$人が乗っています。

  • 変数$N$を$a$で初期化します

駅に到着した時に$b$人が降りて

  • $N$から$b$を引いた値を$N$へ代入します

新たに$c$人が乗車する

  • $N$に$c$を足した値を$N$へ代入します
方針2
  • 直接$a-b+c$を出力します

C
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int n = a;
	n -= b;
	n += c;
	printf("%d\n", n);
	return 0;
}
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	printf("%d\n", a - b + c);
	return 0;
}

C++
#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int n = a;
	n -= b;
	n += c;
	cout << n << endl;
	return 0;
}
#include <iostream>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << a - b + c << endl;
	return 0;
}

C#
using System;

class Program
{
	public static void Main()
	{
		int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int n = abc[0];
		n -= abc[1];
		n += abc[2];
		Console.WriteLine(n);
	}
}
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);
	}
}

Go
package main
import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	n := a
	n -= b
	n += c
	fmt.Println(n)
}
package main
import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	fmt.Println(a - b + c)
}

Java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		n -= sc.nextInt();
		n += sc.nextInt();
		System.out.println(n);
		sc.close();
	}
}
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.close();
	}
}

JavaScript
const [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ').map(Number);
let n = a;
n -= b;
n += c;
console.log(n);
const [a, b, c] = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ').map(Number);
console.log(a - b + c);

Kotlin
fun main() {
	val (a, b, c) = readLine()!!.split(' ').map { it.toInt() }
	var n = a
	n -= b
	n += c
	println(n)
}
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	println(sc.nextInt() - sc.nextInt() + sc.nextInt())
	sc.close()
}

PHP
<?php
	[$a, $b, $c] = array_map("intval", explode(" ", trim(fgets(STDIN))));
	$n = $a;
	$n -= $b;
	$n += $c;
	echo $n, PHP_EOL;
?>
<?php
	[$a, $b, $c] = explode(" ", trim(fgets(STDIN)));
	echo $a - $b + $c, PHP_EOL;
?>

Perl
my ($a, $b, $c) = map { int($_) } split ' ', <STDIN>;
my $n = $a;
$n -= $b;
$n += $c;
print "$n$/";
my ($a, $b, $c) = split ' ', <STDIN>;
print $a - $b + $c, $/;

Python3
a, b, c = map(int, input().split())
n = a
n -= b
n += c
print(n)
a, b, c = map(int, input().split())
print(a - b + c)

Ruby
a, b, c = gets.split.map(&:to_i)
n = a
n -= b
n += c
p n
a, b, c = gets.split.map(&:to_i)
p a - b + c

Scala
import scala.io.StdIn._

object Main extends App{
	val Array(a, b, c) = readLine().split(' ').map(_.toInt)
	var n = a
	n -= b
	n += c
	println(n)
}
import java.util._

object Main extends App{
	val sc = new Scanner(System.in)
	println(sc.nextInt() - sc.nextInt() + sc.nextInt())
	sc.close()
}

Swift
let abc = readLine()!.split(separator: " ").map { Int($0)! }
var n = abc[0]
n -= abc[1]
n += abc[2]
print(n)
let abc = readLine()!.split(separator: " ").compactMap { Int($0) }
let a = abc[0]
let b = abc[1]
let c = abc[2]
print(a - b + c)
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?