1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「電脳少女プログラミング2088 ─壊レタ君を再構築─」〜上半身::"腕だけ銃"取得

Last updated at Posted at 2025-02-06

概要

  • 「電脳少女プログラミング2088 ─壊レタ君を再構築─」をC言語でやりました。(SQL問題は苦労した..ォ)
  • 上半身::"腕だけ銃" を取得するのに、いろんな言語で、paizaスキルチェックをやれ、みたいなのが、あったと思う。
  • わし、C言語しか知らぬ。
  • Dランク問題、でもよい っぽい
  • というわけで、数字を2つ読み取って、足し算するのを各言語まとめてみよう。これができれば、D問題はできるハズ.
  • 各々の言語で、もっと最適な書き方があると思うので、アドバイスいただけたら、と。
    20250206-1.png

仕様

  • 2つの数字を入力としてうけとり、足したものを出力する
    • Input:
    12
    34
    
    • Output:
    46
    

実装例

  • https://onecompiler.com/ という、オンラインの実行環境をサービスしているところがあるので、使用した言語のリンクをつけました。
  • 右側の STDIN に、入力値の 12 と 34 を1行ずついれて、テストしよう

  • Java

    import java.util.*;
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String line = sc.nextLine();
            int num1 = Integer.parseInt(line);
            int num2 = Integer.parseInt(sc.nextLine());
            System.out.println(num1 + num2);
        }
    }
    
  • PHP

    <?php
        $n1 = fgets(STDIN);
        $n2 = fgets(STDIN);
        echo $n1 + $n2
    ?>
    
  • Ruby

    num1 = Integer(gets)
    num2 = Integer(gets)
    puts num1 + num2
    
  • Python2

    n1  = int(raw_input())
    n2  = int(raw_input())
    print n1 + n2
    
  • Python3

    n1 = int(input())
    n2 = int(input())
    print(n1 + n2)
    
  • Perl

    my $n1 = <STDIN>;
    my $n2 = <STDIN>;
    print $n1 + $n2;
    
  • C

    #include <stdio.h>
    int main()
    {
        int num1,num2;
        scanf("%d %d", &num1, &num2);
        printf("%d\n", num1 + num2 );
        return 0;
    }
    
  • C++

    #include <iostream>
    using namespace std;
    int main(void){
        int n1, n2;
        cin >> n1 >> n2;
        cout << n1 + n2 << endl;
        return 0;
    }
    
  • C#

    using System;
    class Program
    {
        static void Main()
        {
            var line = Console.ReadLine();
            int num1 = Int32.Parse(line);
            int num2 = Int32.Parse(Console.ReadLine());
            Console.WriteLine(num1 + num2);
        }
    }
    
  • JS

    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    var nums = [];
    var reader = require('readline').createInterface({
        input: process.stdin,
        output: process.stdout
    });
    reader.on('line', (line) => {
        nums.push(parseInt(line));
    });
    reader.on('close', () => {
        console.log(nums[0] + nums[1]);
    });
    
  • Objective-C

    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    
        int num1,num2;
        scanf("%d %d", &num1, &num2);
        printf("%d\n", num1 + num2 );
    
        [pool release];
        return 0;
    }
    
  • Scala

    object Main extends App {
        val str1 = scala.io.StdIn.readLine
        val str2 = scala.io.StdIn.readLine
        val num1 = str1.toInt
        val num2 = str2.toInt
        println(num1 + num2)
    }
    
  • Go

    package main
    import "fmt"
    
    func main(){
        var num1 int
        var num2 int 
        fmt.Scanf("%d", &num1)
        fmt.Scanf("%d", &num2)
        fmt.Println(num1 + num2)
    }
    
  • Swift

    let n1=Int(readLine()!)!
    let n2=Int(readLine()!)!
    print(n1 + n2)
    
  • Kotlin
    `- https://onecompiler.com/kotlin/

    fun main(args: Array<String>) {
        val str1 = readLine()
        val str2 = readLine()
        val num1: Int? = str1?.toInt()
        var num2: Int = str2!!.toInt()
        println(num1?.plus(num2))
    }
    

感想

  • 使ってない言語は、わからんです...
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?