3
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?

OUPC 2023 Day1のAをいろいろな言語で解く

Last updated at Posted at 2024-01-07

こちらの問題です。

ACが不可能であるTextを除いた全ての言語について、ACが確認出来ました。

><>

0i:48*=?v4c*-$a*+!
v    0:~<
>i:a=?v'0'-+a*
-&,n; >,r~1-:r:&%

AWK

{print int(($1-1)/$2)}

Ada

with Ada.Integer_Text_IO;

procedure Main is
  A, T : Integer;
begin
  Ada.Integer_Text_IO.Get(A);
  Ada.Integer_Text_IO.Get(T);
  Ada.Integer_Text_IO.Put((A - 1)/T,0);
end Main;

Assembly x64

section .data
  int_in_format db "%d", 0
  int_out_format db "%d", 10, 0

section .bss
  a resb 4
  b resb 4

section .text
  global main
  extern scanf, printf

main:
  sub rsp, 8
  lea rdi, [rel int_in_format]
  lea rsi, [rel a]
  call scanf WRT ..plt
  lea rdi, [rel int_in_format]
  lea rsi, [rel b]
  call scanf WRT ..plt
  
  mov eax, [rel a]
  sub eax, 1
  mov ecx, [rel b]
  div ecx

  lea rdi, [rel int_out_format]
  lea rsi, [eax]
  call printf WRT ..plt
  
done:
  add rsp, 8
  mov rax, 0
  ret

bash

read A T
echo $(((A-1)/T))

Brainfuck

[-]>>>>>>>[<<<<<<<+>>>>>>>>+<-]>[-]+<<<<<<<[-]>>>>>>>[<<<<<<<+>>>>>>+>-]<[-]<<<<<[-]>>>>>[<<<<<+>>>>>>+<-]>[-]<<<<<<[>>>>>>+<+<<<<<-]>>>>>[<<<<<+>>>>>-]++++>[-<[>>+>+<<<-]>>>[<<<+>>>-]+<[<<->>>-<[-]]>[<<[-]>>-]<<]<[>+<[-]]>[<<<<<<<[>>>>>>+>>+<<<<<<<<-]>>>>>>>>[<<<<<<<<+>>>>>>>>-]+<<[>>-<<-]+>>[<<->>[-]]+<<[>>>>,<<<<<<<<[-]>>>>>>>>[<<<<<<<<+>>>>>>>>>+<-]>[-]<<<<<<<<<[>>>>>>>>>+<+<<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>-]<<<<-<[-]]>[-]<<[-]<<<<<+[>>>>>+>>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<<[-]>>>[-]<<<<<<<<[>>>>>+>>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]++++<<[->>[<+>>>>>+<<<<-]>>>>[<<<<+>>>>-]+<<<<<[>->>>>-<<<<<[-]]>>>>>[<<<<<<[-]>>>>>>-]<<<<<<]>>[<<+>>[-]]<<[>>>+<<<-]>>>]<<<<<<<<<<[>>>>>>>>>>+<<<+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]+[>>>-<<<-]<<<[>>>+>>+<<<<<-]>>>>>[<<<<<+>>>>>-]>[<+>-]<[<<[>+>>>>>+<<<<<<-]>>>>>>[<<<<<<+>>>>>>-]<<<<<[>>>>>+<<<<-[>>>>[-]>>+<<<<<<-]>>>>>>[<<<<<<+>>>>>>-]<<[<<<<<-[>>-<<[-]]+>>>>>-]<<<<<-]>>+<]<<[-]<[-]>>>>[<<<<+>+>>>-]<<<[-]<[>+>>>+<<<<-]>>>>[<<<<+>>>>-]++++++++++<<<[->>>-<+>[<<+>>>>>+<<<-]>>>[<<<+>>>-]+<<<<<[>>>>>-<<<<<[-]]>>>>>[<<<<[>+<-]>>>>>>+<<-]<<<<<<]>>[>>>+<<<-]>>>>>>[<<<<<<<<+>>>>>>>>-]<<<<<[-]++++++++++<<<[->>>-<+>[<<+>>>>>+<<<-]>>>[<<<+>>>-]+<<<<<[>>>>>-<<<<<[-]]>>>>>[<<<<[>+<-]>>>>>>+<<-]<<<<<<]>>[>>>>>+<<<<<-]>>>>>>[++++++++++++++++++++++++++++++++++++++++++++++++.<<+>+>[-]]<[<[>-<-]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<<++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<[-]

C

#include <stdio.h>
int main(){
    int A,T;
    scanf("%d %d",&A,&T);
    printf("%d\n",(A-1)/T);
}

C#

using System;
class Program
{
    static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int A = int.Parse(input[0]);
		int T = int.Parse(input[1]);
		Console.WriteLine((A-1)/T);
	}
}

C++

#include <iostream>
int main(){
    int A,T;
    std::cin>>A>>T;
    std::cout<<(A-1)/T<<std::endl;
}

COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. Main.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(10).
01 A          PIC  9(03).
01 T          PIC  9(03).
01 G          PIC  ZZZ9.
*> 
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A T.
*>
  COMPUTE G = (A - 1)/T.
  DISPLAY FUNCTION TRIM(G).
*>
  STOP RUN.

Carp

(use IO)
(use String)
(use Int)
(use Array)

(defn getnum []
  (let [ss (get-line)
        s (chomp &ss)]
    (Maybe.unsafe-from (from-string &s))
  )
)

(defn getnums []
  (let [ss (get-line)
        s (words &ss)
        nums (copy-map &Int.from-string &s)]
   nums
  )
)

(defn solve [a b]
  (let [ am (Maybe.unsafe-from a)
         bm (Maybe.unsafe-from b)
         aa (Maybe.unsafe-from am)
         bb (Maybe.unsafe-from bm) ]
   (/ (- aa 1) bb)
  )
)

(defn main []
  (let [
        tmp (getnums)
        AT (solve (first &tmp) (last &tmp))
       ]
  (do
     (print &(Int.str AT))
  )
  )
)

Clojure

(prn (quot (- (read) 1) (read)))

Common Lisp

(format t "~D" (floor (- (read) 1) (read)))

Crystal

a,t=gets.not_nil!.split.map &.to_i
puts (a-1)//t

Cyber

CYBER

tmp = getInput().utf8().split(' ')
A = number(tmp[0])
T = number(tmp[1])
print int((A-1)/T)

D

import std.stdio;
import std.string;
import std.conv;
void main()
{
	string[] input = split(readln());
	int A = to!int(input[0]);
	int T = to!int(input[1]);
	writefln("%d", (A-1)/T);
}

Dart

import 'dart:io';

void main() {
  String tmp = stdin.readLineSync()!;
  int A = int.parse(tmp.split(" ")[0]);
  int T = int.parse(tmp.split(" ")[1]);
  print("${(A-1)~/T}");
}

ECLiPSe

:- lib(ic).

main :-
        read_num(A),
        read_num(T),
        Ans #= (A-1) // T,
        printf("%d%n", [Ans]).

read_str(S) :-
        read_string(user_input, " \n", "", _, S).

read_num(N) :-
	read_str(S),
	number_string(N, S).

Elixir

defmodule Main do
  def main do
    [a,t] = IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)
    div(a-1, t) |> IO.puts()
  end
end

Emacs Lisp

(set-buffer (get-buffer-create "*stdin*"))
(while (ignore-errors (insert (read-string "") "\n") t))
(goto-char (point-min))
(setq standard-input (get-buffer "*stdin*"))

(princ (format "%s" (floor (- (read) 1) (read))))

Erlang

-module('Main').
-export([main/1]).

main(_) ->
    {ok, [A, T]} = io:fread("", "~d~d"),
    io:format("~B ~n", [(A - 1) div T]),
    halt().

F#

let a,t = stdin.ReadLine().Split(" ") |> fun x ->int x[0],int x[1]
printfn "%i" ((a-1)/t)

Factor

USING: kernel io sequences splitting math math.parser ;
readln
" "
split
[ string>number ] map
first2
swap
1
-
swap
/i
number>string
print

Forth

: read-all begin key drop key dup 4 <> tuck if ( emit ) else drop then invert until ; ( read until EOF )
: read-number 0 0 begin swap 10 * + key 48 - dup 0 < until drop ;
: to-bin begin 2 /mod swap 1+ swap dup 0= until drop ; ( convert number to bin array )
: write-pure ( d --  ) dup 0<> if dup 0< if ." -" negate then -1 swap begin dup 0 <> while 10 /mod repeat drop begin dup -1 <> while 48 + emit repeat drop else ." 0" then ;
: write-cr ( d --  ) write-pure cr ;

read-number read-number 
swap 1 - swap /
write-cr

Fortran

program main
  implicit none
  integer :: A,T
  read(*,*) A,T
  print '(i0)', (A-1)/T
end program main

Go

package main

import (
	"fmt"
)

func main() {
	var A, T int
	fmt.Scanf("%d %d", &A, &T)
	fmt.Printf("%d\n", (A-1)/T)
}

Haskell

main :: IO ()
main = do
    [a, t] <- map read . words <$> getLine
    putStrLn $ show ((a - 1) `div` t)

Haxe

using Std;
class Main {
	static function main() {
		var args=Sys.stdin().readLine().split(" ").map(v -> v.parseInt());
		var A=args[0],T=args[1];
		Sys.println(Math.floor((A-1)/T));
	}
}

Java

import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int T = sc.nextInt();
		System.out.println((A-1)/T);
	}
}

JavaScript

function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
	var A = BigInt(tmp[0]);
	var T = BigInt(tmp[1]);
	console.log(((A - 1n) / T).toString());
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Julia

A,T=parse.(Int,split(readline()))
print((A-1)÷T)

Koka

import std/os/readline

fun main()
    val [a, t] = readline().split(" ").map(fn(s) { s.parse-int.unjust })
    println((a - 1) / t)

Kotlin

fun main(args: Array<String>) {
    val (A,T) = readln().split(' ').map { c -> c.toInt() }
    println(String.format("%d", (A-1)/T))
}

LLVM IR

@.str = private unnamed_addr constant [6 x i8] c"%d %d\00", align 1
@.str.1 = private unnamed_addr constant [3 x i8] c"%d\00", align 1
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = call i32 (i8*, ...) @__isoc99_scanf(i8* noundef getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* noundef %1, i32* noundef %2)
  %4 = load i32, i32* %1, align 4
  %5 = sub nsw i32 %4, 1
  %6 = load i32, i32* %2, align 4
  %7 = sdiv i32 %5, %6
  %8 = call i32 (i8*, ...) @printf(i8* noundef getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 noundef %7)
  ret i32 0
}
declare i32 @__isoc99_scanf(i8* noundef, ...)
declare i32 @printf(i8* noundef, ...)

Lua

A, T = io.read("*n", "*n")
print((A - 1) // T)

Mercury

:- module main.
:- interface.

:- import_module io.
:- pred main(io::di, io::uo) is det.

:- implementation.
:- import_module int, list, string.

main(!IO) :-
   io.read_line_as_string(Result, !IO),
   ( if
        Result = ok(Line),
        [AStr, TStr] = string.words(Line),
        string.to_int(AStr, A), string.to_int(TStr, T)
     then
        io.format("%d\n", [i((A - 1)/T)], !IO)
     else
        true
    ).

Nibbles

/-$1;$

Nim

import strutils, sequtils
var
    tmp=readLine(stdin).split().map(parseInt)
    A=tmp[0]
    T=tmp[1]
echo (A-1) div T

OCalm

let () = 
  let a, t = Scanf.scanf " %d %d" (fun i j -> (i, j)) in
  let res = (a - 1)/t in
  Printf.printf "%d\n" res

Octave

[A T] = scanf("%d %d", 'C');
printf("%d\n", floor((A-1)/T))

PHP

<?php
fscanf(STDIN, "%d %d", $A, $T);
echo intdiv($A-1,$T)."\n";
?>

Pascal

var
    A, T : integer;
begin
    read(A);
    readln(T);
    writeln((A-1) div T);
end.

Perl

my $input = <STDIN>;
chomp $input;
my ($A, $T) = split / /, $input;
$ret = int(($A - 1)/$T);
print "$ret\n";

PowerShell

$A,$T= ([Console]::ReadLine()) -split ' '
[int][Math]::Floor(($A - 1) / $T)

Prolog

main :-
  read_num(A),
  read_num(T),
  Res is (A - 1) // T,
  write(Res),
  nl.

read_str(S) :-
  read_string(current_input, ' \n', '', _, S).

read_num(N) :-
	read_str(S),
	number_string(N, S).

Python

A,T = map(int, input().split())
print((A-1)//T)

R

library(magrittr)

s <- readLines("stdin", n=1) %>% strsplit(" ") %>% unlist %>% as.integer

A <- s[1]
T <- s[2]

cat((A - 1) %/% T)

Raku

$/=words>>.Int;say ($0-1) div $1

ReasonML

let inp = read_line();
let res = Scanf.sscanf(inp,"%d %d", ((a, t) => (a-1)/t));
print_endline(string_of_int(res));

Ruby

A,T=gets.chomp.split(" ").map(&:to_i);
print("#{(A-1)/T}\n")

Rust

use proconio::input;
fn main(){
    input!{
        A: i32,
        T: i32
    }
    println!("{}",(A-1)/T);
}

SageMath

A,T = map(int, input().split())
print((A-1)//T)

Scala

import scala.io.StdIn.*
object Main extends App {
    var tmp = readLine.split(" ")
    var A = tmp(0).toInt
    var T = tmp(1).toInt
    println((A-1)/T);
}

Scheme

(define (main args)
  (let* ([a (read)]
         [t (read)])
    (print (quotient (- a 1) t)))
  0)

Sed

s/^\(.*\) \(.*\)$/echo $(((\1-1)\/\2))/e

Seed7

$ include "seed7_05.s7i";

const proc: main is func
  local
    var integer: A is 0;
    var integer: T is 0;
  begin
    read(A);
    read(T);
    writeln((A - 1) div T);
  end func;

Swift

let tmp = readLine()!.split(separator: " ").map { Int($0)! }
let A = tmp[0]
let T = tmp[1]
print("\((A - 1)/T)")

Text

TypeScript

import * as fs from 'fs';
let tmp = fs.readFileSync('/dev/stdin', 'utf8').split(' ');
let A = BigInt(tmp[0]);
let T = BigInt(tmp[1]);
console.log(((A - 1n) / T).toString());

Unison

get_int : '{IO, Exception} Int
get_int = do
  line = !readLine
  Optional.getOrBug "Invalid Input" (Int.fromText line)

get_ints : '{IO, Exception} List(Int)
get_ints = do
  line = !readLine
  w = words line
  v = List.map Int.fromText w
  List.map (Optional.getOrBug "Invalid Input") v

main : '{IO, Exception} ()
main = do
  tmp = get_ints()
  a = List.unsafeAt 0 tmp
  t = List.unsafeAt 1 tmp
  printLine (Int.toText ((a Int.- +1) Int./ t)

V

import os

fn main() {
  tmp := os.get_line().split(' ').map(it.int())
  a := tmp[0]
  t := tmp[1]
  println("${(a - 1) / t}")
}

Vim

dw:let a = @"
dw:let t = @"
:put! = (a - 1) / t
ZZ

Visual Basic

module A
  sub Main(ByVal args() as String)
    Dim line(10) as String
    Dim A as Integer
    Dim T as Integer
    line=Console.ReadLine().Split()
    A = int(line(0))
    T = int(line(1))
    Console.WriteLine((A-1)\T)
  end sub
end module

Whitespace

おそらくコピペしてもACがとれないので、提出リンクを貼っておきます。

https://atcoder.jp/contests/oupc2023-day1/submissions/49183555

 	 					 	   

 	 					 	   
 
	   	
	  	 
		 	 	
 	   	 	 
	
  



   					 	   
   

   						  	 
   
	
	    
			 
    	     
	  	
	  								  
 
    	 	 
	  	
	  								  
 
	   	 	 
	  
   		    
	  		   
 
 						  	 

   								  
 


	



Zig

const std = @import("std");
const stdout = std.io.getStdOut().writer();
const stdin = std.io.getStdIn().reader();

var buff: [100]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buff);
const alloc = fba.allocator();

pub fn main() !void {
  const line = if (try stdin.readUntilDelimiterOrEofAlloc(alloc, '\n', 100)) |str| str else "0 0";
  const index = std.mem.indexOfScalar(u8, line, ' ').?;
  const a = try std.fmt.parseInt(i32, line[0..index], 10);
  const t = try std.fmt.parseInt(i32, line[index + 1..], 10);
  try stdout.print("{}", .{@divTrunc(a-1,t)});
}

Zsh

read A T
echo $(((A-1)/T))

bc

scale=0
(read()-1)/read()

dc

?r1-r/p

jq

split(" ")|map(tonumber)as$tmp|($tmp[0]-1)/$tmp[1]|floor

なでしこ

tmp=「」と尋ねて「 」で区切る。
Aは「{tmp[0]}n」をJS実行。
Tは「{tmp[1]}n」をJS実行。
(A-1n)/Tを表示。

プロデル

【tmp:整数の配列】は、コンソールから受け取ったものを「 」で区切ったもの。
【A:整数】は、tmp(1)。
【T:整数】は、tmp(2)。
(A-1)\Tを表示。

あとがき

並べてみると、ほとんどの言語では小数除算に/が採用されている反面、整数除算は各言語の工夫が見られますね。

追記
littlegirl112さんにいくつかコードをいただきました。ありがとうございます。
KowerKointさんにいくつかコードをいただきました。ありがとうございます。

3
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
3
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?