Skip to content

Commit 9d4f46e

Browse files
committed
Add problem a+b
1 parent 6e18a7b commit 9d4f46e

File tree

20 files changed

+379
-0
lines changed

20 files changed

+379
-0
lines changed

a+b/PROBLEM

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
pid='X'
4+
5+
problem(
6+
time_limit=1.0,
7+
id=pid,
8+
title=pid + "A + B",
9+
#wiki_name="Your pukiwiki page name", # for wikify plugin
10+
#assignees=['Assignees', 'for', 'this', 'problem'], # for wikify plugin
11+
#need_custom_judge=True, # for wikify plugin
12+
reference_solution='java-correct',
13+
)
14+
15+
atcoder_config(
16+
task_id=None # None means a spare
17+
)

a+b/c-correct/SOLUTION

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution definition.
4+
## Choose and modify one of definitions below.
5+
## Adding a parameter challenge_cases marks this solution as a wrong solution.
6+
c_solution(src='main.c')
7+
#cxx_solution(src='main.cc')
8+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main')
9+
#script_solution(src='main.py')

a+b/c-correct/main.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
int t;
5+
scanf("%d", &t);
6+
while (t-- > 0){
7+
int a, b;
8+
scanf("%d %d", &a, &b);
9+
int answer = a + b;
10+
printf("%d\n", answer);
11+
}
12+
return 0;
13+
}

a+b/cpp-correct/SOLUTION

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution definition.
4+
## Choose and modify one of definitions below.
5+
## Adding a parameter challenge_cases marks this solution as a wrong solution.
6+
#c_solution(src='main.c')
7+
cxx_solution(src='main.cpp')
8+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main')
9+
#script_solution(src='main.py')

a+b/cpp-correct/main.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int t;
6+
cin >> t;
7+
for(int i=0; i<t; i++){
8+
int a, b;
9+
cin >> a >> b;
10+
int ans = a + b;
11+
cout << ans << endl;
12+
}
13+
}

a+b/java-correct/AB.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.Scanner;
2+
3+
public class AB {
4+
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
int n = sc.nextInt();
8+
for(int i=0; i<n; i++){
9+
int a = sc.nextInt();
10+
int b = sc.nextInt();
11+
System.out.println(a + b);
12+
}
13+
sc.close();
14+
}
15+
16+
}

a+b/java-correct/SOLUTION

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution
4+
#c_solution(src='main.c') # -lm -O2 as default
5+
#cxx_solution(src='main.cc', flags=[]) # -std=c++11 -O2 as default
6+
java_solution(src='AB.java', encoding='UTF-8', mainclass='AB')
7+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main', challenge_cases=[])
8+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main', challenge_cases=['10_corner*.in'])
9+
#script_solution(src='main.sh') # shebang line is required
10+
#script_solution(src='main.pl') # shebang line is required
11+
#script_solution(src='main.py') # shebang line is required
12+
#script_solution(src='main.rb') # shebang line is required
13+
#js_solution(src='main.js') # javascript (nodejs)
14+
#hs_solution(src='main.hs') # haskell (stack + ghc)
15+
#cs_solution(src='main.cs') # C# (mono)
16+
17+
## Score
18+
#expected_score(100)

a+b/python-correct/SOLUTION

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution definition.
4+
## Choose and modify one of definitions below.
5+
## Adding a parameter challenge_cases marks this solution as a wrong solution.
6+
#c_solution(src='main.c')
7+
#cxx_solution(src='main.cc')
8+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main')
9+
script_solution(src='main.py')

a+b/python-correct/main.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/local/bin/python3
2+
# -*- coding: utf-8 -*-
3+
4+
def solve():
5+
a,b = map(int,input().split())
6+
return a + b
7+
8+
def main():
9+
cases = int(input())
10+
for _ in range(cases):
11+
print(solve())
12+
13+
if __name__ == '__main__':
14+
main()

a+b/ruby-correct/SOLUTION

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution definition.
4+
## Choose and modify one of definitions below.
5+
## Adding a parameter challenge_cases marks this solution as a wrong solution.
6+
#c_solution(src='main.c')
7+
#cxx_solution(src='main.cc')
8+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main')
9+
script_solution(src='main.rb')

a+b/ruby-correct/main.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/ruby
2+
3+
n = gets.to_i
4+
while n>0
5+
a, b = gets.split.map(&:to_i)
6+
puts a+b
7+
n = n-1
8+
end

a+b/shell-correct/SOLUTION

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution
4+
#c_solution(src='main.c') # -lm -O2 as default
5+
#cxx_solution(src='main.cc', flags=[]) # -std=c++11 -O2 as default
6+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main')
7+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main', challenge_cases=[])
8+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main', challenge_cases=['10_corner*.in'])
9+
script_solution(src='main.sh') # shebang line is required
10+
#script_solution(src='main.pl') # shebang line is required
11+
#script_solution(src='main.py') # shebang line is required
12+
#script_solution(src='main.rb') # shebang line is required
13+
#js_solution(src='main.js') # javascript (nodejs)
14+
#hs_solution(src='main.hs') # haskell (stack + ghc)
15+
#cs_solution(src='main.cs') # C# (mono)
16+
17+
## Score
18+
#expected_score(100)

a+b/shell-correct/main.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
sed -e '1d' | awk '{print $1+$2;}'

a+b/statement.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Description
2+
3+
2つの整数 $A, B$ の和を求めよ。
4+
5+
なお、この問題は入出力の練習のために用意されている。
6+
問題の末尾にサンプルプログラムなどが示されているので、参考にせよ。
7+
8+
# Constraints
9+
10+
* $A, B$ は整数
11+
* $-5000 \leq A, B \leq 5000$
12+
13+
# Input
14+
1つの入力ファイルは複数のテストケースからなる。
15+
16+
入力ファイルの最初の1行目にはテストケースの個数 $T$ が記される $(1 \leq T \leq 50)$ 。
17+
18+
2行目以降には、$T$ 個のテストケースが記述されており、各テストケースは次の形式で表される。
19+
20+
```
21+
$A$ $B$
22+
```
23+
24+
# Output
25+
各テストケースに対して、$A+B$ を1行ずつ出力せよ。
26+
27+
# Sample Input
28+
```
29+
3
30+
1 2
31+
-4 2
32+
-100 100
33+
```
34+
35+
# Sample Output
36+
```
37+
3
38+
-2
39+
0
40+
```
41+
42+
# Sample Programs
43+
44+
## C
45+
46+
```
47+
#include &lt;stdio.h&gt;
48+
49+
int main() {
50+
int t;
51+
scanf("%d", &t);
52+
while (t-- > 0){
53+
int a, b;
54+
scanf("%d %d", &a, &b);
55+
int answer = 0; // EDIT HERE
56+
printf("%d\n", answer);
57+
}
58+
return 0;
59+
}
60+
```
61+
62+
## Java
63+
64+
```
65+
import java.util.Scanner;
66+
67+
public class Main {
68+
public static void main(String[] args) {
69+
Scanner sc = new Scanner(System.in);
70+
int n = sc.nextInt();
71+
for(int i=0; i < n; i++){
72+
int a = sc.nextInt();
73+
int b = sc.nextInt();
74+
System.out.println(0); // EDIT HERE
75+
}
76+
sc.close();
77+
}
78+
}
79+
```
80+
81+
# Answer Book
82+
83+
## C
84+
85+
* コンパイル・実行 (C)
86+
87+
```
88+
gcc main.c
89+
./a.out
90+
```
91+
92+
コンパイルでは必要に応じて、``-O2````-Wall``などのコンパイルオプションを使用するとよいかもしれない。
93+
94+
* ファイルから入力する
95+
96+
```
97+
./a.out < in.txt
98+
```
99+
100+
* ファイルへ出力する
101+
102+
```
103+
./a.out > out.txt
104+
```
105+
106+
* ファイル入出力を同時に行う
107+
108+
```
109+
./a.out < in.txt > out.txt
110+
```
111+
112+
## Java
113+
114+
* コンパイル・実行
115+
116+
```
117+
javac Main.java
118+
java Main
119+
```
120+
121+
* ファイルから入力する
122+
123+
```
124+
java Main < in.txt
125+
```
126+
127+
* ファイルへ出力する
128+
129+
```
130+
java Main > out.txt
131+
```
132+
133+
* ファイル入出力を同時に行う
134+
135+
```
136+
java Main < in.txt > out.txt
137+
```
138+
139+
## C++ / Python / Ruby / 他
140+
141+
上記を参考に、自分で調べてください。

a+b/tests/TESTSET

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Input generators.
4+
#c_generator(src='generator.c')
5+
cxx_generator(src='generator.cpp', dependency=['testlib.h'])
6+
#java_generator(src='Generator.java', encoding='UTF-8', mainclass='Generator')
7+
# script_generator(src='generator.py')
8+
9+
## Input validators.
10+
#c_validator(src='validator.c')
11+
cxx_validator(src='validator.cpp', dependency=['testlib.h'])
12+
#java_validator(src='Validator.java', encoding='UTF-8', mainclass='Validator')
13+
#script_validator(src='validator.py')
14+
15+
## Output judges.
16+
#c_judge(src='judge.c')
17+
#cxx_judge(src='judge.cc')
18+
#java_judge(src='Judge.java', encoding='UTF-8', mainclass='Judge')
19+
#script_judge(src='judge.py')

a+b/tests/constraints.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define MAX_T 50
2+
#define MAX_AB 5000
3+

a+b/tests/generator.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <fstream>
2+
#include <string>
3+
#include "testlib.h"
4+
#include "constraints.h"
5+
6+
using namespace std;
7+
const int modified_max = 2017+100;
8+
9+
void generate(const string &file_name, int num_case, int max_num) {
10+
ofstream ofs(file_name);
11+
ofs << num_case <<endl;
12+
13+
for (int i=0; i<num_case; i++) {
14+
ofs << rnd.next(-max_num, max_num) << " ";
15+
ofs << rnd.next(-max_num, max_num) << endl;
16+
}
17+
}
18+
19+
int main(int argc, char* argv[]) {
20+
registerGen(argc, argv, 1);
21+
22+
generate("small.in", 10, 500);
23+
generate("large.in", MAX_T, MAX_AB);
24+
for (int i=0; i<10; i++) {
25+
generate("random_test" + to_string(i) + ".in", MAX_T, MAX_AB);
26+
}
27+
28+
return 0;
29+
}

a+b/tests/sample.diff

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
3
2+
-2
3+
0

a+b/tests/sample.in

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
1 2
3+
-4 2
4+
-100 100

a+b/tests/validator.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "testlib.h"
2+
#include "constraints.h"
3+
#include <iostream>
4+
using namespace std;
5+
6+
void check_case(){
7+
int a = inf.readInt(-MAX_AB, MAX_AB, "a");
8+
inf.readSpace();
9+
int b = inf.readInt(-MAX_AB, MAX_AB, "b");
10+
inf.readEoln();
11+
}
12+
13+
int main(){
14+
registerValidation();
15+
16+
int cases = inf.readInt(1, MAX_T, "cases");
17+
inf.readEoln();
18+
19+
for(int i=0; i<cases; ++i){
20+
check_case();
21+
}
22+
23+
inf.readEof();
24+
return 0;
25+
}

0 commit comments

Comments
 (0)