buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
#include <stdio.h> #include <string.h> int main(void) { int i, n; char *p; char a[1000]; char word[] = "Hoshino"; scanf("%d\n", &n); for (i = 0; i < n; i++) { fgets(a, sizeof(a), stdin); while ((p = strstr(a, "hoshino")) != NULL) { p[6] = 'a'; } printf("%s", a); } return 0; }
#include <stdio.h> #include <string.h> int main(void) { int i, n; char *p; char a[1002]; char word[] = "Hoshino"; scanf("%d\n", &n); for (i = 0; i < n; i++) { fgets(a, sizeof(a), stdin); while ((p = strstr(a, word)) != NULL) { p[6] = 'a'; } printf("%s", a); } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 31, 23, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 31, 23, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 51, 16, 31, 23, 0, 2, 3, 4, 0, 22]]
1
113
6
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { string st; int n; string::size_type id; cin >> n; getchar(); for (n; n > 0; n--) { getline(cin, st); id = 0; while (true) { id = st.find("Hoshino", id); if (id == string::npos) break; st.replace(id, 7, "hoshina"); id++; } cout << st << endl; } return 0; }
#include <iostream> #include <stdio.h> #include <string> using namespace std; int main() { string st; int n; string::size_type id; cin >> n; getchar(); for (n; n > 0; n--) { getline(cin, st); id = 0; while (true) { id = st.find("Hoshino", id); if (id == string::npos) break; st.replace(id, 7, "Hoshina"); id++; } cout << st << endl; } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
113
2
#include <iostream> #include <string> using namespace std; int rep(string a, int *loc) { *loc = a.find("Hoshino"); return *loc; } int main() { string a, t = "Hoshina"; int n, loc; cin >> n; getline(cin, a); while (n--) { loc = 0; getline(cin, a); while (!rep(a, &loc)) a.replace(loc, t.length(), t); cout << a << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int search(string a, int *loc) { *loc = a.find("Hoshino", 0); return *loc; } int main() { string a, t = "Hoshina"; int n, loc; cin >> n; getline(cin, a); while (n--) { loc = 0; getline(cin, a); while (~search(a, &loc)) a.replace(loc, t.length(), t); cout << a << endl; } return 0; }
[["-", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["+", 36, 36, 0, 30, 0, 14, 49, 53, 49, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["-", 8, 9, 0, 52, 15, 339, 51, 91, 17, 111], ["-", 0, 52, 15, 339, 51, 91, 28, 2, 63, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 91, 17, 92], ["+", 0, 52, 15, 339, 51, 91, 28, 2, 63, 22]]
1
120
8
#include <iostream> using namespace std; int main() { string str; int n; cin >> n; cin.ignore(); while (n--) { getline(cin, str); for (int pos = str.find("Hoshino"); pos != string::npos; pos = str.find("Hoshino", 7 + pos)) { str.replace(pos, 7, "Hashina"); } cout << str << endl; } return 0; }
#include <iostream> using namespace std; int main() { string str; int n; cin >> n; cin.ignore(); while (n--) { getline(cin, str); for (int pos = str.find("Hoshino"); pos != string::npos; pos = str.find("Hoshino", 7 + pos)) { str.replace(pos, 7, "Hoshina"); } cout << str << endl; } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
101
2
#include <iostream> #include <string> using namespace std; int main(void) { int D_Set; cin >> D_Set; for (int i = 0; i < D_Set; i++) { string text; getline(cin, text); while (1) { string::size_type pos = text.find("Hoshino"); if (pos == string::npos) { break; } else { text[pos + 6] = 'a'; } } cout << text << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(void) { int D_Set; cin >> D_Set; cin.ignore(); for (int i = 0; i < D_Set; i++) { string text; getline(cin, text); while (1) { string::size_type pos = text.find("Hoshino"); if (pos == string::npos) { break; } else { text[pos + 6] = 'a'; } } cout << text << endl; } return 0; }
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
103
6
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; void Hoshina(string &str) { if (str.size() < 7) { } else { for (unsigned int i = 0; i < str.size() - 6; ++i) { if (str[i] == 'H' && str[i + 1] == 'o' && str[i + 2] == 's' && str[i + 3] == 'h' && str[i + 4] == 'i' && str[i + 5] == 'n' && str[i + 6] == 'o') { str[i + 6] = 'a'; } } } cout << str << endl; } int main() { int n; string str; cin >> n; cin.ignore(); for (int i = 0; i < n; ++i) { getline(cin, str); Hoshina(str); cin.ignore(); } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; void Hoshina(string &str) { if (str.size() < 7) { } else { for (unsigned int i = 0; i < str.size() - 6; ++i) { if (str[i] == 'H' && str[i + 1] == 'o' && str[i + 2] == 's' && str[i + 3] == 'h' && str[i + 4] == 'i' && str[i + 5] == 'n' && str[i + 6] == 'o') { str[i + 6] = 'a'; } } } cout << str << endl; } int main() { int n; string str; cin >> n; cin.ignore(); for (int i = 0; i < n; ++i) { getline(cin, str); Hoshina(str); } return 0; }
[["-", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["-", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["-", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
214
6
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::string text; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { getline(std::cin, text); u_int index = 0; while ((index = text.find(str_false, index)) != std::string::npos) text.replace(index, str_false.size(), str_true); std::cout << text << std::endl; } return 0; }
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::string text; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { getline(std::cin, text); int index = 0; while ((index = text.find(str_false, index)) != std::string::npos) text.replace(index, str_false.size(), str_true); std::cout << text << std::endl; } return 0; }
[["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 78], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40]]
1
131
26
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::string text; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { getline(std::cin, text); int index; while ((index = text.find(str_false, index)) != (int)std::string::npos) text.replace(index, str_false.size(), str_true); std::cout << text << std::endl; } return 0; }
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::string text; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { getline(std::cin, text); int index = 0; while ((index = text.find(str_false, index)) != (int)std::string::npos) text.replace(index, str_false.size(), str_true); std::cout << text << std::endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
1
132
2
n = gets.chomp.to_i n.times do |i| line = gets.chomp line.gsub(/Hoshino/, "Hoshina") puts line end
n = gets.chomp.to_i n.times do |i| line = gets.chomp line.gsub!(/Hoshino/, "Hoshina") puts line end
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
4
34
2
n = gets puts $_.gsub("Hoshiro", "Hoshina") while gets
n = gets puts $_.gsub("Hoshino", "Hoshina") while gets
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
4
18
2
n = gets.to_i n.times do line = gets.chomp! puts line.gsub('Hosino', 'Hoshina') end
n = gets.to_i n.times do line = gets.chomp! puts line.gsub('Hoshino', 'Hoshina') end
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
4
28
2
n = gets().to_i n.times do |i| str = gets() puts str.gsub("hoshino","hoshina") end
# -*- coding: utf-8 -*- n = gets().to_i n.times do |i| str = gets() puts str.gsub("Hoshino", "Hoshina") end
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
4
33
4
#繰り返し回数 count = gets.to_i count.times do #入力された値の"Hoshino"を"Hoshina"に置き換えて表示 p gets.gsub("Hoshino","Hoshina") end
#繰り返し回数 count = gets.to_i count.times do #入力された値の"Hoshino"を"Hoshina"に置き換えて表示 puts gets.gsub("Hoshino","Hoshina") end
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
4
25
2
gets.to_i.times { p gets.chomp.gsub("Hoshino", "Hoshina") }
gets.to_i.times { puts gets.chomp.gsub("Hoshino", "Hoshina") }
[["-", 0, 652, 196, 196, 8, 734, 0, 652, 735, 22], ["+", 0, 652, 196, 196, 8, 734, 0, 652, 735, 22]]
4
22
2
n=int(input()) for i in range(n): print(input().replace("Hoshino","hoshina"))
n=int(input()) for i in range(n): print(input().replace("Hoshino","Hoshina"))
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
5
33
2
[print(input().replace('Hoshino', 'Hoshina')) for _ in range(int(inpu()))]
[print(input().replace('Hoshino', 'Hoshina')) for _ in range(int(input()))]
[["-", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22]]
5
31
2
import sys input() for i in sys.stdin.readlines(): print(i.replace('Hoshino', 'Hoshina'))
import sys input() for i in sys.stdin.readlines(): print(i.replace('Hoshino', 'Hoshina'), end='')
[["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 21], ["+", 0, 1, 0, 652, 3, 4, 0, 653, 141, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 653, 0, 32], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 654], ["+", 0, 652, 3, 4, 0, 653, 51, 557, 0, 655]]
5
31
5
n=int(input()) for i in range(n): s=input() s.replace("Hoshino","Hoshina") print(s)
n=int(input()) for i in range(n): s=input() s=s.replace("Hoshino","Hoshina") print(s)
[["+", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 500, 22]]
5
37
2
import string n=int(raw_input()) for i in range(n): print(raw_input().replace("Hoshino", "Hoshina"))
import string n=int(input()) for i in range(n): print(input().replace("Hoshino", "Hoshina"))
[["-", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["-", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22], ["+", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22]]
5
35
4
num = int(input()) for i in range(num): box = input() box.replace("Hoshino", "Hoshina") print(box)
num = int(input()) for i in range(num): box = input() print(box.replace("Hoshino", "Hoshina"))
[["+", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 7, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22]]
5
37
5
import sys #from me.io import dup_file_stdin #@dup_file_stdin def solve(): for index in range(int(sys.stdin.readline())): print(sys.stdin.readline().replace("Hoshino","Hoshina")) solve()
import sys #from me.io import dup_file_stdin #@dup_file_stdin def solve(): for index in range(int(sys.stdin.readline())): print(sys.stdin.readline()[:-1].replace("Hoshino","Hoshina")) solve()
[["+", 3, 4, 0, 652, 63, 319, 500, 206, 0, 70], ["+", 0, 652, 63, 319, 500, 206, 206, 663, 0, 102], ["+", 63, 319, 500, 206, 206, 663, 0, 664, 17, 33], ["+", 63, 319, 500, 206, 206, 663, 0, 664, 28, 612], ["+", 3, 4, 0, 652, 63, 319, 500, 206, 0, 73]]
5
50
5
for i in [0]*eval(input()):print(input().replace("hino","hina"))
for i in [0]*eval(input()):print(input().replace("Hoshino","Hoshina"))
[["-", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6]]
5
31
4
var print = console.log; function read_input(_input) { var lines = _input.split("\n"); return function() { return lines.shift(); }; } String.prototype.dot = function dot(x) { var res = ""; for (var i = 0; i < x; i++) { res += this.toString(); } return res; }; function IL(line, min1Flg) { var s = line.split(' '); var offset = min1Flg ? -1 : 0; var res = []; for (var i = 0; i < s.length; i++) { res.push(parseInt(s[i])); } return res; } function range(i, n) { var res = []; for (; i < n; i++) { res.push(i); } return res; } function IMAX(x, y) { return x > y ? x : y; } function IMIN(x, y) { return x < y ? x : y; } function item_getter_key(x) { return function(a, b) { if (a[x] < b[x]) return -1; else if (a[x] > b[x]) return 1; return 0; }; } /** * @return {number} */ Array.prototype.SUM = function SUM() { var sum = 0; this.forEach(function(elm) { sum += elm; }); return sum; }; Array.prototype.FORM = function FORM() { return this.map(function(v) { return (' ' + v).slice(-5) }); }; /* (((???????????)??? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? */ // input?????\??????????????¨????????\??? function Main(_input) { var lines = _input.split("\n"); while (lines.length > 0) { var csum = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; var N = lines.shift() - 0; if (N === 0) { return; } for (var i = 0; i < N; i++) { var tmp = IL(lines.shift()); tmp.push(tmp.SUM()); print(tmp.FORM().join('')); for (var j = 0; j < N + 1; j++) { csum[j] += tmp[j]; } } print(csum.splice(0, N + 1).FORM().join('')); } } //*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main???????????????????????? // Main(require("fs").readFileSync("/dev/stdin", "utf8")); Main(require("fs").readFileSync("input.txt", "utf8"));
var print = console.log; function read_input(_input) { var lines = _input.split("\n"); return function() { return lines.shift(); }; } String.prototype.dot = function dot(x) { var res = ""; for (var i = 0; i < x; i++) { res += this.toString(); } return res; }; function IL(line, min1Flg) { var s = line.split(' '); var offset = min1Flg ? -1 : 0; var res = []; for (var i = 0; i < s.length; i++) { res.push(parseInt(s[i])); } return res; } function range(i, n) { var res = []; for (; i < n; i++) { res.push(i); } return res; } function IMAX(x, y) { return x > y ? x : y; } function IMIN(x, y) { return x < y ? x : y; } function item_getter_key(x) { return function(a, b) { if (a[x] < b[x]) return -1; else if (a[x] > b[x]) return 1; return 0; }; } /** * @return {number} */ Array.prototype.SUM = function SUM() { var sum = 0; this.forEach(function(elm) { sum += elm; }); return sum; }; Array.prototype.FORM = function FORM() { return this.map(function(v) { return (' ' + v).slice(-5) }); }; /* (((???????????)??? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? */ // input?????\??????????????¨????????\??? function Main(_input) { var lines = _input.split("\n"); while (lines.length > 0) { var csum = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; var N = lines.shift() - 0; if (N === 0) { return; } for (var i = 0; i < N; i++) { var tmp = IL(lines.shift()); tmp.push(tmp.SUM()); print(tmp.FORM().join('')); for (var j = 0; j < N + 1; j++) { csum[j] += tmp[j]; } } print(csum.splice(0, N + 1).FORM().join('')); } } //*???????????\????????¨??????????????§????????????????¨??????\????????????????????????????????????Main???????????????????????? Main(require("fs").readFileSync("/dev/stdin", "utf8")); // Main(require("fs").readFileSync("input.txt", "utf8"));
[["-", 3, 3, 0, 2, 3, 3, 0, 557, 0, 491], ["+", 3, 3, 0, 2, 3, 3, 0, 557, 0, 491]]
2
569
2
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; int[][] a = new int[n + 1][n + 1]; int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = sc.nextInt(); sum += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][n] += a[i][j]; a[n][j] += a[j][i]; } } a[n][n] = sum; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { System.out.printf("%5d", a[i][j]); } System.out.println(); } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; int[][] a = new int[n + 1][n + 1]; int sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = sc.nextInt(); sum += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][n] += a[i][j]; a[n][j] += a[i][j]; } } a[n][n] = sum; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { System.out.printf("%5d", a[i][j]); } System.out.println(); } } } }
[["-", 0, 1, 0, 11, 12, 504, 516, 504, 71, 22], ["+", 0, 1, 0, 11, 12, 504, 516, 504, 71, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 504, 71, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 504, 71, 22]]
3
272
4
#include <stdio.h> int main(void) { int n; int mat[11][11] = {0}; int i, j; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &mat[i][j]); mat[i][n] += mat[i][j]; mat[n][j] += mat[i][j]; } mat[n][n] += mat[i][n]; } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%4d", mat[i][j]); mat[i][j] = 0; } printf("\n"); } } return (0); }
#include <stdio.h> int main(void) { int n; int mat[11][11] = {0}; int i, j; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &mat[i][j]); mat[i][n] += mat[i][j]; mat[n][j] += mat[i][j]; } mat[n][n] += mat[i][n]; } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%5d", mat[i][j]); mat[i][j] = 0; } printf("\n"); } } return (0); }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
215
2
#include <stdio.h> #include <stdlib.h> #include <string.h> void matrix_like_computation(const int); void listen_input(int *[], const int); void calc_sums(int *[], const int); void echo_matrix(int *[], const int); int main() { int data_count; while (scanf("%d", &data_count), data_count) { matrix_like_computation(data_count); } return 0; } void matrix_like_computation(const int data_count) { int prep_roop; int matrix[11][11]; int *export_matrix[11]; for (prep_roop = 0; prep_roop < 11; prep_roop++) { export_matrix[prep_roop] = matrix[prep_roop]; } listen_input(export_matrix, data_count); calc_sums(export_matrix, data_count); echo_matrix(export_matrix, data_count); } void listen_input(int *matrix[], const int data_count) { int ver_count, hor_count; char input_buff[64]; for (ver_count = 0; ver_count < data_count; ver_count++) { while (fgets(input_buff, sizeof(input_buff), stdin), !strcmp(input_buff, "\n")) ; matrix[0][ver_count] = atoi(strtok(input_buff, " ")); for (hor_count = 1; hor_count < data_count; hor_count++) { matrix[hor_count][ver_count] = atoi(strtok(NULL, " ")); } } } void calc_sums(int *matrix[], const int data_count) { int ver_count, hor_count, ver_sum, hor_sum, all_sum = 0; //横と全合計 for (ver_count = 0; ver_count < data_count; ver_count++) { hor_sum = 0; for (hor_count = 0; hor_count < data_count; hor_count++) { hor_sum += matrix[hor_count][ver_count]; all_sum += matrix[hor_count][ver_count]; } matrix[data_count][ver_count] = hor_sum; } matrix[data_count][data_count] = all_sum; //縦 for (hor_count = 0; hor_count < data_count; hor_count++) { ver_sum = 0; for (ver_count = 0; ver_count < data_count; ver_count++) { ver_sum += matrix[hor_count][ver_count]; } matrix[hor_count][data_count] = hor_sum; } } void echo_matrix(int *matrix[], const int data_count) { int ver_count, hor_count; for (ver_count = 0; ver_count <= data_count; ver_count++) { for (hor_count = 0; hor_count <= data_count; hor_count++) { printf("%5d", matrix[hor_count][ver_count]); } printf("\n"); } }
#include <stdio.h> #include <stdlib.h> #include <string.h> void matrix_like_computation(const int); void listen_input(int *[], const int); void calc_sums(int *[], const int); void echo_matrix(int *[], const int); int main() { int data_count; while (scanf("%d", &data_count), data_count) { matrix_like_computation(data_count); } return 0; } void matrix_like_computation(const int data_count) { int prep_roop; int matrix[11][11]; int *export_matrix[11]; for (prep_roop = 0; prep_roop < 11; prep_roop++) { export_matrix[prep_roop] = matrix[prep_roop]; } listen_input(export_matrix, data_count); calc_sums(export_matrix, data_count); echo_matrix(export_matrix, data_count); } void listen_input(int *matrix[], const int data_count) { int ver_count, hor_count; char input_buff[64]; for (ver_count = 0; ver_count < data_count; ver_count++) { while (fgets(input_buff, sizeof(input_buff), stdin), !strcmp(input_buff, "\n")) ; matrix[0][ver_count] = atoi(strtok(input_buff, " ")); for (hor_count = 1; hor_count < data_count; hor_count++) { matrix[hor_count][ver_count] = atoi(strtok(NULL, " ")); } } } void calc_sums(int *matrix[], const int data_count) { int ver_count, hor_count, ver_sum, hor_sum, all_sum = 0; //横と全合計 for (ver_count = 0; ver_count < data_count; ver_count++) { hor_sum = 0; for (hor_count = 0; hor_count < data_count; hor_count++) { hor_sum += matrix[hor_count][ver_count]; all_sum += matrix[hor_count][ver_count]; } matrix[data_count][ver_count] = hor_sum; } matrix[data_count][data_count] = all_sum; //縦 for (hor_count = 0; hor_count < data_count; hor_count++) { ver_sum = 0; for (ver_count = 0; ver_count < data_count; ver_count++) { ver_sum += matrix[hor_count][ver_count]; } matrix[hor_count][data_count] = ver_sum; } } void echo_matrix(int *matrix[], const int data_count) { int ver_count, hor_count; for (ver_count = 0; ver_count <= data_count; ver_count++) { for (hor_count = 0; hor_count <= data_count; hor_count++) { printf("%5d", matrix[hor_count][ver_count]); } printf("\n"); } }
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
0
507
2
#include <stdio.h> int main(void) { for (;;) { int n, i, j, hyo[12][12] = {{0}}, w = 0, all = 0; scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &hyo[i][j]); w += hyo[i][j]; if (j == n - 1) { hyo[i][j + 1] = w; w = 0; } } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { w += hyo[j][i]; if (j == n - 1) { hyo[j + 1][i] = w; all += w; w = 0; } } } hyo[n][n] = all; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { if (hyo[i][j] > 9999) printf("%d", hyo[i][j]); else if (hyo[i][j] > 999) printf(" %d", hyo[i][j]); else if (hyo[i][j] > 99) printf(" %d", hyo[i][j]); else if (hyo[i][j] > 9) printf(" %d", hyo[i][j]); else if (hyo[i][j] < 10) printf(" %d", hyo[i][j]); if (j == n) puts("\n"); } } } return 0; }
#include <stdio.h> int main(void) { for (;;) { int n, i, j, hyo[12][12] = {{0}}, w = 0, all = 0; scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &hyo[i][j]); w += hyo[i][j]; if (j == n - 1) { hyo[i][j + 1] = w; w = 0; } } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { w += hyo[j][i]; if (j == n - 1) { hyo[j + 1][i] = w; all += w; w = 0; } } } hyo[n][n] = all; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { if (hyo[i][j] > 9999) printf("%d", hyo[i][j]); else if (hyo[i][j] > 999) printf(" %d", hyo[i][j]); else if (hyo[i][j] > 99) printf(" %d", hyo[i][j]); else if (hyo[i][j] > 9) printf(" %d", hyo[i][j]); else if (hyo[i][j] < 10) printf(" %d", hyo[i][j]); if (j == n) printf("\n"); } } } return 0; }
[["-", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 2, 63, 22]]
0
410
2
#include <stdio.h> int main(void) { int i, j, ans[10] = {0}, n, tmp, sum; while (scanf("%d", &n) != EOF) { for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &tmp); if (i == 0) ans[j] = tmp; else ans[j] += tmp; if (j == 0) sum = tmp; else sum += tmp; printf("%5d", tmp); } printf("%5d\n", sum); } for (i = 0, sum = 0; i < n; i++) { printf("%5d", ans[i]); sum += ans[i]; } printf("%5d\n", sum); } return 0; }
#include <stdio.h> int main(void) { int i, j, ans[10] = {0}, n, tmp, sum; while (scanf("%d", &n), n) { for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &tmp); if (i == 0) ans[j] = tmp; else ans[j] += tmp; if (j == 0) sum = tmp; else sum += tmp; printf("%5d", tmp); } printf("%5d\n", sum); } for (i = 0, sum = 0; i < n; i++) { printf("%5d", ans[i]); sum += ans[i]; } printf("%5d\n", sum); } return 0; }
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 23, 0, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 23, 0, 34, 12, 22]]
0
191
4
#include <stdio.h> int a[16][16]; int main(void) { int n; int i, j; while (1) { scanf("%d", &n); if (n == 0) break; a[n][n] = 0; for (i = 0; i < n; i++) { a[i][n] = 0; for (j = 0; j < n; j++) { scanf("%d", &a[i][j]); a[i][n] += a[i][j]; } a[n][n] += a[i][n]; } for (i = 0; i < n; i++) { a[n][i] = 0; for (j = 0; j < n; j++) { a[n][i] += a[i][j]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%5d", a[i][j]); } printf("\n"); } } return (0); }
#include <stdio.h> int a[16][16]; int main(void) { int n; int i, j; while (1) { scanf("%d", &n); if (n == 0) break; a[n][n] = 0; for (i = 0; i < n; i++) { a[i][n] = 0; for (j = 0; j < n; j++) { scanf("%d", &a[i][j]); a[i][n] += a[i][j]; } a[n][n] += a[i][n]; } for (i = 0; i < n; i++) { a[n][i] = 0; for (j = 0; j < n; j++) { a[n][i] += a[j][i]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%5d", a[i][j]); } printf("\n"); } } return (0); }
[["-", 0, 1, 0, 11, 12, 69, 28, 69, 71, 22], ["+", 0, 1, 0, 11, 12, 69, 28, 69, 71, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 69, 71, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 71, 22]]
0
261
4
#include <stdio.h> int main(int argc, char **argv) { int dataset, i, j; int data[11][11]; scanf("%d", &dataset); while (dataset != 0) { for (i = 0; i <= dataset; i++) for (j = 0; j <= dataset; j++) data[i][j] = 0; for (i = 0; i < dataset; i++) { for (j = 0; j < dataset; j++) { scanf("%d", &data[i][j]); data[i][dataset] += data[i][j]; data[dataset][j] += data[i][j]; } data[dataset][dataset] += data[i][dataset]; } for (i = 0; i <= dataset; i++) { for (j = 0; j <= dataset; j++) printf("%4d", data[i][j]); printf("\n"); } scanf("%d", &dataset); } return 0; }
#include <stdio.h> int main(int argc, char **argv) { int dataset, i, j; int data[11][11]; scanf("%d", &dataset); while (dataset != 0) { for (i = 0; i <= dataset; i++) for (j = 0; j <= dataset; j++) data[i][j] = 0; for (i = 0; i < dataset; i++) { for (j = 0; j < dataset; j++) { scanf("%d", &data[i][j]); data[i][dataset] += data[i][j]; data[dataset][j] += data[i][j]; } data[dataset][dataset] += data[i][dataset]; } for (i = 0; i <= dataset; i++) { for (j = 0; j <= dataset; j++) printf("%5d", data[i][j]); printf("\n"); } scanf("%d", &dataset); } return 0; }
[["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
242
2
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int m[11][11], n, i, j, t; for (; scanf("%d", &n) && n != 0;) { memset(m, 0, sizeof(m)); for (i = 0; i <= n; i++) for (j = 0; j <= n; j++) { if (i < n && j < n) { scanf("%d", &t); m[i][j] = t; m[i][n] += t; m[n][j] += t; m[n][n] += t; } printf("%5d", m[i][j]); } printf("\n"); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int m[11][11], n, i, j, t; for (; scanf("%d", &n) && n != 0;) { memset(m, 0, sizeof(m)); for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { if (i < n && j < n) { scanf("%d", &t); m[i][j] = t; m[i][n] += t; m[n][j] += t; m[n][n] += t; } printf("%5d", m[i][j]); } printf("\n"); } } return 0; }
[["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46]]
0
176
2
#include <stdio.h> int main() { int n, i, j, val[11][11]; scanf("%d", &n); while (n != 0) { val[n][n] = 0; for (i = 0; i < n; i++) { val[i][n] = 0; val[n][i] = 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &val[i][j]); val[n][n] += val[i][j]; val[i][n] += val[i][j]; val[n][j] += val[i][j]; } } for (i = 0; i <= n; i++) { for (i = 0; i <= n; i++) { printf("%5d", val[i][j]); } printf("\n"); } scanf("%d", &n); } return 0; }
#include <stdio.h> int main() { int n, i, j, val[11][11]; scanf("%d", &n); while (n != 0) { val[n][n] = 0; for (i = 0; i < n; i++) { val[i][n] = 0; val[n][i] = 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &val[i][j]); val[n][n] += val[i][j]; val[i][n] += val[i][j]; val[n][j] += val[i][j]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%5d", val[i][j]); } printf("\n"); } scanf("%d", &n); } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 10, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 10, 11, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22]]
0
245
6
#include <stdio.h> int main() { int i, j, n, tmp = 0, total = 0; while (scanf("%d", &n)) { if (n == 0) { break; } int mas[n + 1][n + 1]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &mas[i][j]); tmp += mas[i][j]; } mas[i][n] = tmp; total += tmp; tmp = 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { tmp += mas[j][i]; } mas[n][i] = tmp; tmp = 0; } mas[n][n] = total; printf("\n"); for (i = 0; i < n + 1; i++) { for (j = 0; j < n + 1; j++) { printf("%5d", mas[i][j]); } printf("\n"); } total = 0; } return 0; }
#include <stdio.h> int main() { int i, j, n, tmp = 0, total = 0; while (scanf("%d", &n)) { if (n == 0) { break; } int mas[n + 1][n + 1]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &mas[i][j]); tmp += mas[i][j]; } mas[i][n] = tmp; total += tmp; tmp = 0; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { tmp += mas[j][i]; } mas[n][i] = tmp; tmp = 0; } mas[n][n] = total; for (i = 0; i < n + 1; i++) { for (j = 0; j < n + 1; j++) { printf("%5d", mas[i][j]); } printf("\n"); } total = 0; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
268
7
#include <stdio.h> int main(void) { int total[11]; int i, n, k, s, val; while (1) { scanf("%d", &n); if (!n) break; for (i = 0; i <= n; i++) { total[i] = 0; } for (i = 0; i < n; i++) { s = 0; for (k = 0; k < n; k++) { scanf("%d", &val); total[i] += val; s += val; printf("%5d", val); } total[k] += s; printf("%5d\n", s); } for (i = 0; i <= n; i++) { printf("%5d", total[i]); } putchar('\n'); } return 0; }
#include <stdio.h> int main(void) { int total[11]; int i, n, k, s, val; while (1) { scanf("%d", &n); if (!n) break; for (i = 0; i <= n; i++) { total[i] = 0; } for (i = 0; i < n; i++) { s = 0; for (k = 0; k < n; k++) { scanf("%d", &val); total[k] += val; s += val; printf("%5d", val); } total[k] += s; printf("%5d\n", s); } for (i = 0; i <= n; i++) { printf("%5d", total[i]); } putchar('\n'); } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22], ["+", 8, 9, 0, 1, 0, 11, 31, 69, 71, 22]]
0
189
2
#include <stdio.h> #include <string.h> int main() { int i, j, n, matrix[11][11]; while (scanf("%d", &n)) { if (!0) break; memset(matrix, 0, sizeof(matrix)); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &matrix[i][j]); matrix[i][n] += matrix[i][j]; matrix[n][j] += matrix[i][j]; matrix[n][n] += matrix[i][j]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%5d", matrix[i][j]); } puts(""); } } return 0; }
#include <stdio.h> #include <string.h> int main() { int i, j, n, matrix[11][11]; while (scanf("%d", &n)) { if (!n) break; memset(matrix, 0, sizeof(matrix)); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &matrix[i][j]); matrix[i][n] += matrix[i][j]; matrix[n][j] += matrix[i][j]; matrix[n][n] += matrix[i][j]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { printf("%5d", matrix[i][j]); } puts(""); } } return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 91, 28, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 91, 28, 22]]
0
206
2
#include <memory.h> #include <stdio.h> int main(void) { int i, j, n, t; int A[20][20]; while (scanf("%d\n", &n) == 1) { if (n == 0) break; memset((char *)A, 0x00, sizeof(A)); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &t); A[i][j] = t; A[i][n] += t; A[n][j] += t; A[n][n] += t; } } for (i = 0; i < n + 1; i++) { for (j = 0; j < n + 1; j++) { printf("%5d", A[i][j]); } printf("\n"); } printf("\n"); } return 0; }
#include <memory.h> #include <stdio.h> int main(void) { int i, j, n, t; int A[20][20]; while (scanf("%d\n", &n) == 1) { if (n == 0) break; memset((char *)A, 0x00, sizeof(A)); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &t); A[i][j] = t; A[i][n] += t; A[n][j] += t; A[n][n] += t; } } for (i = 0; i < n + 1; i++) { for (j = 0; j < n + 1; j++) { printf("%5d", A[i][j]); } printf("\n"); } } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
216
7
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <typeinfo> #include <vector> #define INF 100000000 #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; typedef long long ll; int main() { int n; while (cin >> n) { if (n == 0) break; int data[20][20] = {}; rep(i, n) { rep(j, n) { cin >> data[i][j]; } } rep(i, n) { int sum = 0; rep(j, n) sum += data[i][j]; data[i][n] = sum; } rep(j, n + 1) { int sum = 0; rep(i, n) sum += data[i][j]; data[n][j] = sum; } rep(i, n + 1) { rep(j, n + 1) { printf("%4d", data[i][j]); } cout << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <typeinfo> #include <vector> #define INF 100000000 #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; typedef long long ll; int main() { int n; while (cin >> n) { if (n == 0) break; int data[20][20] = {}; rep(i, n) { rep(j, n) { cin >> data[i][j]; } } rep(i, n) { int sum = 0; rep(j, n) sum += data[i][j]; data[i][n] = sum; } rep(j, n + 1) { int sum = 0; rep(i, n) sum += data[i][j]; data[n][j] = sum; } rep(i, n + 1) { rep(j, n + 1) { printf("%5d", data[i][j]); } cout << endl; } } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
228
2
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) int main() { int n; while (cin >> n, n) { int table[n][n], x[n], y[n], sum = 0; REP(i, n) { REP(j, n) cin >> table[i][j]; x[i] = y[i] = 0; } REP(i, n) { cout << setw(4) << right << table[i][0]; x[i] = table[i][0]; FOR(j, 1, n) { cout << setw(4) << right << table[i][j]; x[i] += table[i][j]; } cout << setw(4) << right << x[i] << endl; } REP(i, n) { REP(j, n) y[i] += table[j][i]; } cout << setw(4) << right << y[0]; FOR(i, 1, n) cout << setw(4) << right << y[i]; REP(i, n) sum += x[i]; cout << setw(4) << right << sum << endl; } }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) int main() { int n; while (cin >> n, n) { int table[n][n], x[n], y[n], sum = 0; REP(i, n) { REP(j, n) cin >> table[i][j]; x[i] = y[i] = 0; } REP(i, n) { cout << setw(5) << right << table[i][0]; x[i] = table[i][0]; FOR(j, 1, n) { cout << setw(5) << right << table[i][j]; x[i] += table[i][j]; } cout << setw(5) << right << x[i] << endl; } REP(i, n) { REP(j, n) y[i] += table[j][i]; } cout << setw(5) << right << y[0]; FOR(i, 1, n) cout << setw(5) << right << y[i]; REP(i, n) sum += x[i]; cout << setw(5) << right << sum << endl; } }
[["-", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 31, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
1
286
12
#include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { int excel[11][11] = {}; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> excel[i][j]; excel[n][n] += excel[i][j] * 2; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { excel[i][n] += excel[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { excel[n][i] += excel[j][i]; } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { printf("%5d", excel[i][j]); if (j == n) { cout << endl; } } } } return 0; }
#include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { int excel[11][11] = {}; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> excel[i][j]; excel[n][n] += excel[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { excel[i][n] += excel[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { excel[n][i] += excel[j][i]; } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { printf("%5d", excel[i][j]); if (j == n) { cout << endl; } } } } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
255
2
#include <bits/stdc++.h> using namespace std; int n; int main() { while (cin >> n) { if (!n) break; int data[n + 1][n + 1]; for (int i = 0; i < n; ++i) { int tmp, sum; for (int j = 0; j < n; ++j) { cin >> tmp; data[i][j] = tmp; sum += tmp; } data[i][n] = sum; } int sump = 0; for (int i = 0; i < n; ++i) { int summ = 0; for (int j = 0; j < n; ++j) { summ += data[j][i]; } data[n][i] = summ; sump += summ; } data[n][n] = sump; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { // cout << " " << data[i][j]; printf("%5d", data[i][j]); } cout << endl; // printf("\n"); } } return 0; }
#include <bits/stdc++.h> using namespace std; int n; int main() { while (cin >> n) { if (!n) break; int data[n + 1][n + 1]; for (int i = 0; i < n; ++i) { int tmp = 0, sum = 0; for (int j = 0; j < n; ++j) { cin >> tmp; data[i][j] = tmp; sum += tmp; } data[i][n] = sum; } int sump = 0; for (int i = 0; i < n; ++i) { int summ = 0; for (int j = 0; j < n; ++j) { summ += data[j][i]; } data[n][i] = summ; sump += summ; } data[n][n] = sump; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { // cout << " " << data[i][j]; printf("%5d", data[i][j]); } cout << endl; // printf("\n"); } } return 0; }
[["+", 0, 7, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
1
240
4
#include <iomanip> #include <iostream> using namespace std; int main(void) { int n; int i, j; while (1) { cin >> n; if (n == 0) { break; } int array[11][11] = {}; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> array[i][j]; array[i][n] = array[i][n] + array[i][j]; array[n][j] = array[n][j] + array[i][j]; array[n][n] = array[n][n] + array[i][j]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { std::cout << std::right << std::setw(4) << array[i][j]; } cout << endl; } } return 0; }
#include <iomanip> #include <iostream> using namespace std; int main(void) { int n; int i, j; while (1) { cin >> n; if (n == 0) { break; } int array[11][11] = {}; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> array[i][j]; array[i][n] = array[i][n] + array[i][j]; array[n][j] = array[n][j] + array[i][j]; array[n][n] = array[n][n] + array[i][j]; } } for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { std::cout << std::right << std::setw(5) << array[i][j]; } cout << endl; } } return 0; }
[["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
1
227
2
#include <cstdio> #include <iostream> using namespace std; int main() { int n, h[11][11]; while (scanf("%d", &n)) { if (!n) break; for (int i = 0; i < n; i++) { int num = 0; for (int j = 0; j < n; j++) { scanf("%d", &h[i][j]); num += h[i][j]; printf("%5d", h[i][j]); } h[i][n] = num; printf("%5d\n", num); } for (int i = 0; i <= n; i++) { int num = 0; for (int j = 0; j < n; j++) num += h[j][i]; printf("%5d", num); } } }
#include <cstdio> #include <iostream> using namespace std; int main() { int n, h[11][11]; while (scanf("%d", &n)) { if (!n) break; for (int i = 0; i < n; i++) { int num = 0; for (int j = 0; j < n; j++) { scanf("%d", &h[i][j]); num += h[i][j]; printf("%5d", h[i][j]); } h[i][n] = num; printf("%5d\n", num); } for (int i = 0; i <= n; i++) { int num = 0; for (int j = 0; j < n; j++) num += h[j][i]; printf("%5d", num); } printf("\n"); } }
[["+", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
198
7
#include <bits/stdc++.h> using namespace std; #define all(vec) vec.begin(), vec.end() typedef long long int ll; typedef pair<ll, ll> P; const ll MOD = 10000; const ll INF = 1000000010; const ll LINF = 1000000000000000010; const int MAX = 100001; int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1}; ll keta(ll n) { int d = 0; while (n > 0) { n /= 10; d++; } return d; } int main() { int n; while (cin >> n, n) { int a[12][12] = {}; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; a[i][n] += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[n][i] += a[j][i]; } } for (int i = 0; i < n; i++) { a[n][n] += a[n][i]; } cout << endl; for (int i = 0; i <= n; i++, cout << endl) { for (int j = 0; j <= n; j++) { printf("%5d", a[i][j]); } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define all(vec) vec.begin(), vec.end() typedef long long int ll; typedef pair<ll, ll> P; const ll MOD = 10000; const ll INF = 1000000010; const ll LINF = 1000000000000000010; const int MAX = 100001; int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1}; ll keta(ll n) { int d = 0; while (n > 0) { n /= 10; d++; } return d; } int main() { int n; while (cin >> n, n) { int a[12][12] = {}; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; a[i][n] += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[n][i] += a[j][i]; } } for (int i = 0; i < n; i++) { a[n][n] += a[n][i]; } for (int i = 0; i <= n; i++, cout << endl) { for (int j = 0; j <= n; j++) { printf("%5d", a[i][j]); } } } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
357
4
#include <iomanip> #include <iostream> using namespace std; int main() { int n; int area[11][11]; while (cin >> n) { if (n == 0) break; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> area[i][j]; } } for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { count += area[i][j]; } area[i][n] = count; } for (int j = 0; j <= n; j++) { int count = 0; for (int i = 0; i < n; i++) { count += area[i][j]; } area[n][j] = count; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { cout << setw(4) << area[i][j]; } cout << endl; } } return 0; }
#include <iomanip> #include <iostream> using namespace std; int main() { int n; int area[11][11]; while (cin >> n) { if (n == 0) break; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> area[i][j]; } } for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { count += area[i][j]; } area[i][n] = count; } for (int j = 0; j <= n; j++) { int count = 0; for (int i = 0; i < n; i++) { count += area[i][j]; } area[n][j] = count; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { cout << setw(5) << area[i][j]; } cout << endl; } } return 0; }
[["-", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13]]
1
252
2
#include <cstdio> int main(void) { int data[11][11]; int n; while (1) { scanf("%d", &n); if (n == 0) break; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { data[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &data[i][j]); data[i][n] += data[i][j]; data[n][j] += data[i][j]; data[n][n] += data[i][j]; } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { printf("%5d", data[i][j]); } printf("\n"); } } return (0); }
#include <cstdio> int main(void) { int data[11][11]; int n; while (1) { scanf("%d", &n); if (n == 0) break; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { data[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &data[i][j]); data[i][n] += data[i][j]; data[n][j] += data[i][j]; data[n][n] += data[i][j]; } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { printf("%5d", data[i][j]); } printf("\n"); } } return (0); }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
242
4
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int N; while (cin >> N, N) { int num[150][150] = {{0}}; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> num[i][j]; num[i][N] += num[i][j]; num[N][j] += num[i][j]; num[N][N] += num[i][j]; } } for (int i = 0; i <= N; i++) { for (int j = 1; j <= N; j++) { if (num[i][j] < 10) { for (int k = 0; k < 4; k++) cout << " "; } else if (num[i][j] < 100) { for (int k = 0; k < 3; k++) cout << " "; } else if (num[i][j] < 1000) { for (int k = 0; k < 2; k++) cout << " "; } else if (num[i][j] < 10000) { for (int k = 0; k < 1; k++) cout << " "; } cout << num[i][j]; } cout << endl; } } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int N; while (cin >> N, N) { int num[150][150] = {{0}}; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> num[i][j]; num[i][N] += num[i][j]; num[N][j] += num[i][j]; num[N][N] += num[i][j]; } } for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { if (num[i][j] < 10) { for (int k = 0; k < 4; k++) cout << " "; } else if (num[i][j] < 100) { for (int k = 0; k < 3; k++) cout << " "; } else if (num[i][j] < 1000) { for (int k = 0; k < 2; k++) cout << " "; } else if (num[i][j] < 10000) { for (int k = 0; k < 1; k++) cout << " "; } cout << num[i][j]; } cout << endl; } } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
324
2
#include <stdio.h> int main() { int n; while (1) { int l, r; int a[11][11]; scanf("%d", &n); if (!n) break; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } for (int i = 0; i < n + 1; i++) { l = r = 0; for (int j = 0; j < n; j++) { l += a[i][j]; r += a[j][i]; } a[i][n] = l; a[n][i] = r; } for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) printf("%4d", a[i][j]); printf("\n"); } } return 0; }
#include <stdio.h> int main() { int n; while (1) { int l, r; int a[11][11]; scanf("%d", &n); if (!n) break; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } for (int i = 0; i < n + 1; i++) { l = r = 0; for (int j = 0; j < n; j++) { l += a[i][j]; r += a[j][i]; } a[i][n] = l; a[n][i] = r; } for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) printf("%5d", a[i][j]); printf("\n"); } } return 0; }
[["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
233
2
#include <iomanip> #include <iostream> int main() { int n; int *table; while (1) { std::cin >> n; if (!n) { return 0; } table = new int[(n + 1) * (n + 1)]; for (int i = 0; i < n * n; i++) { std::cin >> table[i / n * (n + 1) + i % n]; } for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { table[r * (n + 1) + n] += table[r * (n + 1) + c]; table[n * (n + 1) + c] += table[r * (n + 1) + c]; table[n * (n + 1) + n] += table[r * (n + 1) + c]; } } for (int i = 0; i < (n + 1) * (n + 1); i++) { std::cout << std::setw(5) << std::right << table[i]; if (i % (n + 1) == n) { std::cout << std::endl; } } delete[] table; } }
#include <iomanip> #include <iostream> int main() { int n; int *table; while (1) { std::cin >> n; if (!n) { return 0; } table = new int[(n + 1) * (n + 1)](); for (int i = 0; i < n * n; i++) { std::cin >> table[i / n * (n + 1) + i % n]; } for (int r = 0; r < n; r++) { for (int c = 0; c < n; c++) { table[r * (n + 1) + n] += table[r * (n + 1) + c]; table[n * (n + 1) + c] += table[r * (n + 1) + c]; table[n * (n + 1) + n] += table[r * (n + 1) + c]; } } for (int i = 0; i < (n + 1) * (n + 1); i++) { std::cout << std::setw(5) << std::right << table[i]; if (i % (n + 1) == n) { std::cout << std::endl; } } delete[] table; } }
[["+", 0, 1, 0, 11, 12, 350, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 350, 3, 4, 0, 25]]
1
279
2
num=[] while gets x=[] y=[] z=0 s=$_.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
loop do num=[] x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
[["+", 36, 36, 36, 36, 36, 36, 0, 42, 0, 22], ["+", 36, 36, 36, 36, 36, 36, 0, 42, 0, 170], ["-", 36, 36, 36, 36, 36, 36, 0, 42, 0, 89], ["-", 36, 36, 36, 36, 36, 36, 0, 42, 0, 22], ["-", 36, 36, 0, 42, 0, 662, 12, 652, 486, 744], ["+", 36, 36, 0, 42, 0, 662, 12, 652, 486, 22]]
4
63
6
while n = STDIN.gets.to_i do break if n == 0 twodarr = [] n.times{ |i| arr = STDIN.gets.split.map(&:to_i) twodarr[i] = arr } (n).times{ |i| twodarr[i][twodarr.size] = twodarr[i].inject(:+) (twodarr.size+2).times{ |j| print twodarr[i][j].to_s.rjust(5) } puts "" } rowsum = [] rowsum = twodarr.transpose.map{|ary| ary.inject(&:+)} (twodarr.size+1).times{ |i| print rowsum[i].to_s.rjust(5) } end
while n = STDIN.gets.to_i do break if n == 0 twodarr = [] n.times{ |i| arr = STDIN.gets.split.map(&:to_i) twodarr[i] = arr } n.times{ |i| twodarr[i][twodarr.size] = twodarr[i].inject(:+) (twodarr.size+1).times{ |j| print twodarr[i][j].to_s.rjust(5) } puts } rowsum = [] rowsum = twodarr.transpose.map{|ary| ary.inject(&:+)} (twodarr.size+1).times{ |i| print rowsum[i].to_s.rjust(5) } puts end
[["-", 0, 89, 8, 170, 0, 652, 486, 739, 0, 24], ["-", 0, 89, 8, 170, 0, 652, 486, 739, 0, 25], ["-", 8, 734, 0, 652, 486, 739, 0, 738, 12, 612], ["+", 8, 734, 0, 652, 486, 739, 0, 738, 12, 612], ["-", 8, 734, 0, 652, 3, 4, 0, 557, 0, 62], ["+", 36, 36, 0, 493, 0, 89, 8, 170, 0, 22]]
4
156
7
#include <algorithm> #include <assert.h> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define ALL(s) (s).begin(), (s).end() #define ITE(c) typeof((c).begin()) #define clr(a) memset((a), 0, sizeof(a)) #define nclr(a) memset((a), -1, sizeof(a)) #define pb push_back #define INRANGE(x, s, e) ((s) <= (x) && (x) < (e)) #define MP(a, b) make_pair((a), (b)) using namespace std; int vis[128][128]; char dat[128][128]; int main() { int w, h; while (cin >> w >> h, w || h) { rep(i, 128) { rep(j, 128) { vis[j][i] = 0; dat[j][i] = 0; } } rep(i, h) { rep(j, w) { cin >> dat[j][i]; } } int px = 0, py = 0; while (dat[px][py] != '.') { if (vis[px][py]) break; vis[px][py] = 1; switch (dat[px][py]) { case '>': px++; break; case '<': px--; break; case '^': py--; break; case 'v': py++; break; } } if (vis[px][py]) { cout << "LOOP" << endl; } else { cout << px << " " << py << endl; } } return 0; }
#include <algorithm> #include <assert.h> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define ALL(s) (s).begin(), (s).end() #define ITE(c) typeof((c).begin()) #define clr(a) memset((a), 0, sizeof(a)) #define nclr(a) memset((a), -1, sizeof(a)) #define pb push_back #define INRANGE(x, s, e) ((s) <= (x) && (x) < (e)) #define MP(a, b) make_pair((a), (b)) using namespace std; int vis[128][128]; char dat[128][128]; int main() { int w, h; while (cin >> h >> w, w || h) { rep(i, 128) { rep(j, 128) { vis[j][i] = 0; dat[j][i] = 0; } } rep(i, h) { rep(j, w) { cin >> dat[j][i]; } } int px = 0, py = 0; while (dat[px][py] != '.') { if (vis[px][py]) break; vis[px][py] = 1; switch (dat[px][py]) { case '>': px++; break; case '<': px--; break; case '^': py--; break; case 'v': py++; break; } } if (vis[px][py]) { cout << "LOOP" << endl; } else { cout << px << " " << py << endl; } } return 0; }
[["-", 15, 339, 51, 34, 31, 16, 31, 16, 12, 22], ["-", 0, 52, 15, 339, 51, 34, 31, 16, 17, 152], ["+", 0, 52, 15, 339, 51, 34, 31, 16, 17, 152], ["+", 0, 52, 15, 339, 51, 34, 31, 16, 12, 22]]
1
372
4
#include <cstdio> #include <iostream> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) int main(void) { int w, h; char map[100][100]; while (cin >> w >> h, w | h) { rep(j, h) rep(i, w) cin >> map[i][j]; int x = 0, y = 0; while (true) { if (map[x][y] == '@') { cout << "LOOP" << endl; break; } if (map[x][y] == '>') { x++; map[x - 1][y] = '@'; } else if (map[x][y] == '<') { x--; map[x + 1][y] = '@'; } else if (map[x][y] == 'v') { y++; map[x][y - 1] = '@'; } else if (map[x][y] == '^') { y--; map[x][y + 1] = '@'; } else { cout << x << " " << y << endl; break; } } } return 0; }
#include <cstdio> #include <iostream> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) int main(void) { int w, h; char map[100][100]; while (cin >> h >> w, w | h) { rep(j, h) rep(i, w) cin >> map[i][j]; int x = 0, y = 0; while (true) { if (map[x][y] == '@') { cout << "LOOP" << endl; break; } if (map[x][y] == '>') { x++; map[x - 1][y] = '@'; } else if (map[x][y] == '<') { x--; map[x + 1][y] = '@'; } else if (map[x][y] == 'v') { y++; map[x][y - 1] = '@'; } else if (map[x][y] == '^') { y--; map[x][y + 1] = '@'; } else { cout << x << " " << y << endl; break; } } } return 0; }
[["-", 15, 339, 51, 34, 31, 16, 31, 16, 12, 22], ["-", 0, 52, 15, 339, 51, 34, 31, 16, 17, 152], ["+", 0, 52, 15, 339, 51, 34, 31, 16, 17, 152], ["+", 0, 52, 15, 339, 51, 34, 31, 16, 12, 22]]
1
279
4
#include <iostream> #include <vector> using namespace std; int main() { int w, h; int i, j; while (1) { cin >> w; cin >> h; if (w == 0 || h == 0) break; vector<vector<char>> v(101, vector<char>(101)); for (j = 0; j < h; ++j) { for (i = 0; i < w; ++i) { cin >> v[i][j]; } } int mi = 0, mj = 0; while (true) { char c = v[mi][mj]; v[mi][mj] = '#'; if (c == '>') mi++; else if (c == '<') mi--; else if (c == '^') mj--; else if (c == 'v') mj++; else if (c == '#') { cout << "LOOP" << endl; break; } else if (c == '.') { cout << mi << ' ' << mj << endl; break; } } } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int w, h; int i, j; while (1) { cin >> h; cin >> w; if (w == 0 || h == 0) break; vector<vector<char>> v(101, vector<char>(101)); for (j = 0; j < h; ++j) { for (i = 0; i < w; ++i) { cin >> v[i][j]; } } int mi = 0, mj = 0; while (true) { char c = v[mi][mj]; v[mi][mj] = '#'; if (c == '>') mi++; else if (c == '<') mi--; else if (c == '^') mj--; else if (c == 'v') mj++; else if (c == '#') { cout << "LOOP" << endl; break; } else if (c == '.') { cout << mi << ' ' << mj << endl; break; } } } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
244
4
#include <iostream> using namespace std; char tile[150][150]; bool flag[150][150]; int solve(int x, int y) { if (flag[x][y]) return -1; int ans; flag[x][y] = true; switch (tile[x][y]) { case '>': ans = solve(x + 1, y); break; case '<': ans = solve(x - 1, y); break; case 'v': ans = solve(x, y + 1); break; case '^': ans = solve(x, y - 1); break; case '.': ans = x * 1000 + y; break; default: break; } return ans; } int main() { int W, H, ans; while (1) { cin >> W >> H; if (W == 0 && H == 0) break; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { flag[j][i] = false; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> tile[j][i]; } } if ((ans = solve(0, 0)) == -1) cout << "LOOP" << endl; else cout << ans / 1000 << " " << ans % 1000 << endl; } return 0; }
#include <iostream> using namespace std; char tile[150][150]; bool flag[150][150]; int solve(int x, int y) { if (flag[x][y]) return -1; int ans; flag[x][y] = true; switch (tile[x][y]) { case '>': ans = solve(x + 1, y); break; case '<': ans = solve(x - 1, y); break; case 'v': ans = solve(x, y + 1); break; case '^': ans = solve(x, y - 1); break; case '.': ans = x * 1000 + y; break; default: break; } return ans; } int main() { int W, H, ans; while (1) { cin >> H >> W; if (W == 0 && H == 0) break; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { flag[j][i] = false; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> tile[j][i]; } } if ((ans = solve(0, 0)) == -1) cout << "LOOP" << endl; else cout << ans / 1000 << " " << ans % 1000 << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22]]
1
331
4
#include <iostream> using namespace std; int main() { int H, W, x, y; while (cin >> H >> W) { if (H == 0 && W == 0) break; char space[H][W], c; for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { cin >> space[j][i]; } } x = y = 0; while (1) { c = space[x][y]; space[x][y] = '0'; if (c == '>') x++; else if (c == '<') x--; else if (c == 'v') y++; else if (c == '^') y--; else if (c == '.') { cout << x << ' ' << y << endl; break; } else if (c == '0') { cout << "LOOP" << endl; break; } } } return 0; }
#include <iostream> using namespace std; int main() { int H, W, x, y; while (cin >> H >> W) { if (H == 0 && W == 0) break; char space[W][H], c; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> space[j][i]; } } x = y = 0; while (1) { c = space[x][y]; space[x][y] = '0'; if (c == '>') x++; else if (c == '<') x--; else if (c == 'v') y++; else if (c == '^') y--; else if (c == '.') { cout << x << ' ' << y << endl; break; } else if (c == '0') { cout << "LOOP" << endl; break; } } } return 0; }
[["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 22], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 22], ["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 22], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 22], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
226
8
#include <iostream> using namespace std; int main() { int a, b, i, j; char map[102][102]; while (1) { cin >> a >> b; if (a + b == 0) break; for (i = 0; i < a; i++) { for (j = 0; j < b; j++) { cin >> map[i][j]; } } i = 0, j = 0; while (1) { if (map[i][j] == '.') { cout << j << " " << i << endl; break; } else if (map[i][j] == '#') { cout << "loop" << endl; break; } else if (map[i][j] == '>') { map[i][j] = '#'; j++; } else if (map[i][j] == '<') { map[i][j] = '#'; j--; } else if (map[i][j] == '^') { map[i][j] = '#'; i--; } else if (map[i][j] == 'v') { map[i][j] = '#'; i++; } } } return 0; }
#include <iostream> using namespace std; int main() { int a, b, i, j; char map[102][102]; while (1) { cin >> a >> b; if (a + b == 0) break; for (i = 0; i < a; i++) { for (j = 0; j < b; j++) { cin >> map[i][j]; } } i = 0, j = 0; while (1) { if (map[i][j] == '.') { cout << j << " " << i << endl; break; } else if (map[i][j] == '#') { cout << "LOOP" << endl; break; } else if (map[i][j] == '>') { map[i][j] = '#'; j++; } else if (map[i][j] == '<') { map[i][j] = '#'; j--; } else if (map[i][j] == '^') { map[i][j] = '#'; i--; } else if (map[i][j] == 'v') { map[i][j] = '#'; i++; } } } return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
294
2
#include <stdio.h> int main() { int i, j, w, h; char c, m[101][101]; bool b[101][101], loop; while (1) { scanf("%d %d", &w, &h); if (!w && !h) break; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { do { scanf("%c", &c); m[i][j] = c; } while (c == '\n' || c == '\r'); } } for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { b[i][j] = false; } } i = j = 0; loop = false; while (1) { if (b[i][j]) { loop = true; break; } b[i][j] = true; c = m[i][j]; if (c == '>') ++j; else if (c == '<') --j; else if (c == '^') --i; else if (c == 'v') ++i; else break; } if (!loop) { printf("%d %d\n", j, i); } else { printf("LOOP\n"); } } return 0; }
#include <stdio.h> int main() { int i, j, w, h; char c, m[101][101]; bool b[101][101], loop; while (1) { scanf("%d %d", &h, &w); if (!w && !h) break; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { do { scanf("%c", &c); m[i][j] = c; } while (c == '\n' || c == '\r'); } } for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { b[i][j] = false; } } i = j = 0; loop = false; while (1) { if (b[i][j]) { loop = true; break; } b[i][j] = true; c = m[i][j]; if (c == '>') ++j; else if (c == '<') --j; else if (c == '^') --i; else if (c == 'v') ++i; else break; } if (!loop) { printf("%d %d\n", j, i); } else { printf("LOOP\n"); } } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22]]
1
313
4
def onTile tile, x, y (0 <= x && x < tile[0].length) && (0 <= y && y < tile.length) end def onArrow tile, x, y tile[y][x] == ">" || tile[y][x] == "<" || tile[y][x] == "^" || tile[y][x] == "v" end def createTile width, height tile = Array.new height.times do tile << $stdin.gets.chomp.split("") end tile end def solve tile, x, y visited = Array.new(tile.length).map{Array.new(tile[0].length, false)} while (onTile(tile, x, y) && !visited[y][x] && onArrow(tile, x, y)) do visited[y][x] = true case tile[y][x] when ">" then x += 1 when "v" then y += 1 when "<" then x -= 1 when "^" then y -= 1 else #do nothing end end visited[y][x] ? "LOOP" : (x.to_s + " " + y.to_s) end height, widht = $stdin.gets.chomp.split(" ").map(&:to_i) while width > 0 && height > 0 do puts solve(createTile(width, height), 0, 0) height, width = $stdin.gets.chomp.split(" ").map(&:to_i) end
def onTile tile, x, y (0 <= x && x < tile[0].length) && (0 <= y && y < tile.length) end def onArrow tile, x, y tile[y][x] == ">" || tile[y][x] == "<" || tile[y][x] == "^" || tile[y][x] == "v" end def createTile width, height tile = Array.new height.times do tile << $stdin.gets.chomp.split("") end tile end def solve tile, x, y visited = Array.new(tile.length).map{Array.new(tile[0].length, false)} while (onTile(tile, x, y) && !visited[y][x] && onArrow(tile, x, y)) do visited[y][x] = true case tile[y][x] when ">" then x += 1 when "v" then y += 1 when "<" then x -= 1 when "^" then y -= 1 else #do nothing end end visited[y][x] ? "LOOP" : (x.to_s + " " + y.to_s) end height, width = $stdin.gets.chomp.split(" ").map(&:to_i) while width > 0 && height > 0 do puts solve(createTile(width, height), 0, 0) height, width = $stdin.gets.chomp.split(" ").map(&:to_i) end
[["-", 36, 36, 0, 493, 0, 662, 31, 761, 0, 22], ["+", 36, 36, 0, 493, 0, 662, 31, 761, 0, 22]]
4
330
2
loop do w, h = gets.chomp.split.map(&:to_i) break if [w, h].all?(&:zero?) tile_map = Array.new h.times do |i| tile_map[i] = gets.chomp.split('') end x = y = 0 tile_already_arrived = Array.new h.times { tile_already_arrived << Array.new(w, false) } is_loop = false while true tile = tile_map[y][x] if tile_already_arrived[y][x] == true is_loop = true break else tile_already_arrived[y][x] = true case tile when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = [x,y] break end end end if is_loop puts "LOOP" else puts "#{goal[0]} #{goal[1]}" end end
loop do h, w = gets.chomp.split.map(&:to_i) break if [w, h].all?(&:zero?) tile_map = Array.new h.times do |i| tile_map[i] = gets.chomp.split('') end x = y = 0 tile_already_arrived = Array.new h.times { tile_already_arrived << Array.new(w, false) } is_loop = false while true tile = tile_map[y][x] if tile_already_arrived[y][x] == true is_loop = true break else tile_already_arrived[y][x] = true case tile when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = [x,y] break end end end if is_loop puts "LOOP" else puts "#{goal[0]} #{goal[1]}" end end
[["-", 196, 737, 8, 736, 0, 662, 31, 761, 0, 22], ["-", 196, 737, 8, 736, 0, 662, 31, 761, 0, 21], ["+", 196, 737, 8, 736, 0, 662, 31, 761, 0, 21], ["+", 196, 737, 8, 736, 0, 662, 31, 761, 0, 22]]
4
190
4
loop do h, w = gets.chomp.split.map(&:to_i) break if [h, w].all?(&:zero?) tile_map = tile_already_arrived = Array.new h.times do tile_map << gets.chomp.split('') tile_already_arrived << Array.new(w, false) end x = y = 0 while true tile_present = tile_map[y][x] if tile_already_arrived[y][x] == true goal = "LOOP" break else tile_already_arrived[y][x] = true case tile_present when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = "#{x} #{y}" break end end end puts goal end
loop do h, w = gets.chomp.split.map(&:to_i) break if [h, w].all?(&:zero?) tile_map = Array.new tile_already_arrived = Array.new h.times do tile_map << gets.chomp.split('') tile_already_arrived << Array.new(w, false) end x = y = 0 while true tile_present = tile_map[y][x] if tile_already_arrived[y][x] == true goal = "LOOP" break else tile_already_arrived[y][x] = true case tile_present when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = "#{x} #{y}" break end end end puts goal end
[["+", 196, 737, 8, 736, 0, 662, 12, 652, 486, 743], ["+", 196, 737, 8, 736, 0, 662, 12, 652, 17, 131], ["+", 196, 737, 8, 736, 0, 662, 12, 652, 735, 22]]
4
157
20
import sys import math def decide_move(x,y,tile,check): if tile == '<': x -= 1 check[x][y] += 1 return x,y,check elif tile == '>': x += 1 check[x][y] += 1 return x,y,check elif tile == '^': y -= 1 check[x][y] += 1 return x,y,check else: y += 1 check[x][y] += 1 return x,y,check while True: h,w = map(int,input().split()) if h == 0: break tile_map = [] for i in range(h): tile_map.append(input()) check =[[0 for i in range(w)]for j in range(h)] check[0][0] = 1 x = 0 y = 0 status = 0 while True: if tile_map[x][y] == '.': status = 1 print(y,x) break x,y,check = decide_move(x,y,tile_map[x][y],check) if check[x][y] > 1: status = 1 print('LOOP') break
import sys import math def decide_move(x,y,tile,check): if tile == '<': y -= 1 check[x][y] += 1 return x,y,check elif tile == '>': y += 1 check[x][y] += 1 return x,y,check elif tile == '^': x -= 1 check[x][y] += 1 return x,y,check else: x += 1 check[x][y] += 1 return x,y,check while True: h,w = map(int,input().split()) if h == 0: break tile_map = [] for i in range(h): tile_map.append(input()) check =[[0 for i in range(w)]for j in range(h)] check[0][0] = 1 x = 0 y = 0 status = 0 while True: if tile_map[x][y] == '.': status = 1 print(y,x) break x,y,check = decide_move(x,y,tile_map[x][y],check) if check[x][y] > 1: status = 1 print('LOOP') break
[["-", 0, 57, 64, 196, 0, 1, 0, 677, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 677, 31, 22], ["-", 75, 665, 64, 196, 0, 1, 0, 677, 31, 22], ["+", 75, 665, 64, 196, 0, 1, 0, 677, 31, 22], ["-", 75, 76, 8, 196, 0, 1, 0, 677, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 677, 31, 22]]
5
264
8
DIR = {">": (0, 1), "<": (0, -1), "^": (-1, 0), "v": (1, 0)} while True: w, h = m(int, input().split()) if w == 0 and h == 0: break m = [] for i in range(w): m.append([c for c in input().strip()]) x = 0 y = 0 while m[x][y] != '.': i = m[x][y] if i == 'x': break m[x][y] = 'x' x += DIR[i][0] y += DIR[i][1] if m[x][y] == '.': print(("{} {}".format(y, x))) else: print("LOOP")
DIR = {">": (0, 1), "<": (0, -1), "^": (-1, 0), "v": (1, 0)} while True: w, h = list(map(int, input().split())) if w == 0 and h == 0: break m = [] for i in range(w): m.append([c for c in input().strip()]) x = 0 y = 0 while m[x][y] != '.': i = m[x][y] if i == 'x': break m[x][y] = 'x' x += DIR[i][0] y += DIR[i][1] if m[x][y] == '.': print(("{} {}".format(y, x))) else: print("LOOP")
[["-", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
205
5
import java.util.PriorityQueue; import java.util.Scanner; public class Main { static class Dic implements Comparable<Dic> { String moji; int page; Dic(String moji, int page) { this.moji = moji; this.page = page; } public int compareTo(Dic d) { if (this.moji == d.moji) { return this.page - d.page; } else { return this.moji.compareTo(d.moji); } } } public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { PriorityQueue<Dic> pq = new PriorityQueue<>(); while (sc.hasNextLine()) { String str = sc.nextLine(); String[] token = str.split(" "); String s = token[0]; int n = Integer.parseInt(token[1]); pq.add(new Dic(s, n)); } String pre = ""; while (!pq.isEmpty()) { Dic dic = pq.poll(); if (dic.moji.equals(pre)) { System.out.println(" " + dic.page); } else if (pre.equals("")) { System.out.println(dic.moji); System.out.print(dic.page); } else { System.out.println(); System.out.println(dic.moji); System.out.print(dic.page); } pre = dic.moji; } System.out.println(); } } }
import java.util.PriorityQueue; import java.util.Scanner; public class Main { static class Dic implements Comparable<Dic> { String moji; int page; Dic(String moji, int page) { this.moji = moji; this.page = page; } public int compareTo(Dic d) { if (this.moji.equals(d.moji)) { return this.page - d.page; } else { return this.moji.compareTo(d.moji); } } } public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { PriorityQueue<Dic> pq = new PriorityQueue<>(); while (sc.hasNextLine()) { String str = sc.nextLine(); String[] token = str.split(" "); String s = token[0]; int n = Integer.parseInt(token[1]); pq.add(new Dic(s, n)); } String pre = ""; while (!pq.isEmpty()) { Dic dic = pq.poll(); if (dic.moji.equals(pre)) { System.out.print(" " + dic.page); } else if (pre.equals("")) { System.out.println(dic.moji); System.out.print(dic.page); } else { System.out.println(); System.out.println(dic.moji); System.out.print(dic.page); } pre = dic.moji; } System.out.println(); } } }
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 15, 0, 492, 0, 131], ["+", 8, 196, 0, 57, 15, 15, 0, 492, 141, 22], ["+", 0, 57, 15, 15, 0, 492, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 15, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 492, 141, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 492, 141, 22]]
3
345
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.TreeMap; public class Main { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; TreeMap<String, ArrayList<Integer>> index = new TreeMap<String, ArrayList<Integer>>(); while ((line = br.readLine()) != null) { if (line.isEmpty()) break; String[] spl = line.split(" "); String moji = spl[0]; int kazu = Integer.parseInt(spl[1]); if (index.containsKey(moji)) { index.get(kazu).add(kazu); Collections.sort(index.get(kazu)); } else { ArrayList<Integer> al1 = new ArrayList<Integer>(); al1.add(kazu); index.put(moji, al1); } } // End WHILE for (String key : index.keySet()) { System.out.println(key); ArrayList al2 = index.get(key); for (int i = 0; i < al2.size(); i++) { System.out.print(al2.get(i)); if (i < al2.size() - 1) { System.out.print(" "); } else { System.out.println(""); } } } } catch (Exception e) { e.printStackTrace(); } } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.TreeMap; public class Main { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; TreeMap<String, ArrayList<Integer>> index = new TreeMap<String, ArrayList<Integer>>(); while ((line = br.readLine()) != null) { if (line.isEmpty()) break; String[] spl = line.split(" "); String moji = spl[0]; int kazu = Integer.parseInt(spl[1]); if (index.containsKey(moji)) { index.get(moji).add(kazu); Collections.sort(index.get(moji)); } else { ArrayList<Integer> al1 = new ArrayList<Integer>(); al1.add(kazu); index.put(moji, al1); } } // End WHILE for (String key : index.keySet()) { System.out.println(key); ArrayList al2 = index.get(key); for (int i = 0; i < al2.size(); i++) { System.out.print(al2.get(i)); if (i < al2.size() - 1) { System.out.print(" "); } else { System.out.println(""); } } } } catch (Exception e) { e.printStackTrace(); } } }
[["-", 0, 1, 0, 492, 500, 492, 3, 4, 0, 22], ["+", 0, 1, 0, 492, 500, 492, 3, 4, 0, 22], ["-", 0, 492, 3, 4, 0, 492, 3, 4, 0, 22], ["+", 0, 492, 3, 4, 0, 492, 3, 4, 0, 22]]
3
344
4
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Map<String, List<Integer>> memo = new TreeMap<String, List<Integer>>(); while (scanner.hasNext()) { String word = scanner.next(); int page = scanner.nextInt(); if (!memo.containsKey(word)) { memo.put(word, new ArrayList<Integer>()); memo.get(word).add(page); } } for (Entry<String, List<Integer>> entry : memo.entrySet()) { Collections.sort(entry.getValue()); System.out.println(entry.getKey()); for (int i = 0; i < entry.getValue().size(); i++) { if (i != 0) { System.out.print(" "); } System.out.print(entry.getValue().get(i)); } System.out.println(); } } }
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.TreeMap; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Map<String, List<Integer>> memo = new TreeMap<String, List<Integer>>(); while (scanner.hasNext()) { String word = scanner.next(); int page = scanner.nextInt(); if (!memo.containsKey(word)) { memo.put(word, new ArrayList<Integer>()); } memo.get(word).add(page); } for (Entry<String, List<Integer>> entry : memo.entrySet()) { Collections.sort(entry.getValue()); System.out.println(entry.getKey()); for (int i = 0; i < entry.getValue().size(); i++) { if (i != 0) { System.out.print(" "); } System.out.print(entry.getValue().get(i)); } System.out.println(); } } }
[["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
3
284
2
#include <bits/stdc++.h> using namespace std; int main(void) { pair<string, int> t[1010]; int i; for (i = 0; cin >> t[i].first >> t[i].second; i++) ; sort(t, t + i); cout << t[0].first << "\n"; cout << t[1].second; for (int j = 1; j < i; j++) { if (t[j - 1].first == t[j].first) { cout << " " << t[j].second; } else { cout << "\n"; cout << t[j].first << "\n"; cout << t[j].second; } } cout << "\n"; }
#include <bits/stdc++.h> using namespace std; int main(void) { pair<string, int> t[1010]; int i; for (i = 0; cin >> t[i].first >> t[i].second; i++) ; sort(t, t + i); cout << t[0].first << "\n"; cout << t[0].second; for (int j = 1; j < i; j++) { if (t[j - 1].first == t[j].first) { cout << " " << t[j].second; } else { cout << "\n"; cout << t[j].first << "\n"; cout << t[j].second; } } cout << "\n"; }
[["-", 0, 16, 12, 118, 28, 69, 341, 342, 0, 13], ["+", 0, 16, 12, 118, 28, 69, 341, 342, 0, 13]]
1
170
2
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; #define INF 1 << 20 struct edge { int to; int cost; edge(){}; edge(int a, int b) { to = a; cost = b; } }; struct Node { int pos; int cost; Node(){}; Node(int a, int b) { pos = a; cost = b; } bool operator<(const Node &rhs) const { return cost > rhs.cost; } }; void dijkistra(int st, int TO, int V, vector<vector<edge>> graph) { priority_queue<Node> q; vector<int> d(V); for (int i = 0; i < V; i++) { d[i] = INF; } d[st] = 0; q.push(Node(st, 0)); while (!q.empty()) { Node s = q.top(); q.pop(); int pos = s.pos; for (int i = 0; i < graph[pos].size(); i++) { int to = graph[pos][i].to; int cost = graph[pos][i].cost; if (d[pos] + cost < d[to]) { d[to] = d[pos] + cost; q.push(Node(to, d[to])); } } } cout << d[TO] << endl; } int partition(int A[], int p, int r) { int x = A[r]; int i = p - 1; for (int j = p; j < r; j++) { if (x >= A[j]) { i = i + 1; swap(A[i], A[j]); } } swap(A[i + 1], A[r]); return i + 1; } void quicksort(int A[], int p, int r) { if (p < r) { int q = partition(A, p, r); quicksort(A, p, q - 1); quicksort(A, q + 1, r); } } int getNumberOfCoin(int C[], int n, int m) { int T[50000]; for (int j = 0; j <= n; j++) { T[j] = INF; } T[0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j <= n; j++) { if (j - C[i] >= 0) { T[j] = min(T[j], T[j - C[i]] + 1); } } } return T[n]; } int knapsack(int w, int n, int *v, int *ww) { int W[101][10001]; for (int j = 0; j <= w; j++) { W[0][j] = 0; } for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { for (int j = 0; j <= w; j++) { if (j - ww[k] < 0) { W[i + 1][j] = W[i][j]; } if (j - ww[i] >= 0) { W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]); } } } } return W[n][w]; } int fib(int n) { vector<int> v(n + 1); v[0] = 1; v[1] = 1; for (int i = 2; i < n + 1; i++) { v[i] = v[i - 2] + v[i - 1]; } return v[n]; } int main() { map<string, vector<int>> dic; string voc; int page; while (cin >> voc >> page) { dic[voc].push_back(page); } map<string, vector<int>>::iterator it = dic.begin(); while (it != dic.end()) { cout << (*it).first << endl; sort((*it).second.begin(), (*it).second.end()); for (int i = 0; i < (*it).second.size(); i++) { if (i = (*it).second.size() - 1) { cout << (*it).second[i]; } else cout << (*it).second[i] << " "; } cout << endl; it++; } } int isPrime(int x) { if (x <= 1) return false; if (x > 2 && x % 2 == 0) return false; for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return false; } } if (x == 2) return true; return true; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; #define INF 1 << 20 struct edge { int to; int cost; edge(){}; edge(int a, int b) { to = a; cost = b; } }; struct Node { int pos; int cost; Node(){}; Node(int a, int b) { pos = a; cost = b; } bool operator<(const Node &rhs) const { return cost > rhs.cost; } }; void dijkistra(int st, int TO, int V, vector<vector<edge>> graph) { priority_queue<Node> q; vector<int> d(V); for (int i = 0; i < V; i++) { d[i] = INF; } d[st] = 0; q.push(Node(st, 0)); while (!q.empty()) { Node s = q.top(); q.pop(); int pos = s.pos; for (int i = 0; i < graph[pos].size(); i++) { int to = graph[pos][i].to; int cost = graph[pos][i].cost; if (d[pos] + cost < d[to]) { d[to] = d[pos] + cost; q.push(Node(to, d[to])); } } } cout << d[TO] << endl; } int partition(int A[], int p, int r) { int x = A[r]; int i = p - 1; for (int j = p; j < r; j++) { if (x >= A[j]) { i = i + 1; swap(A[i], A[j]); } } swap(A[i + 1], A[r]); return i + 1; } void quicksort(int A[], int p, int r) { if (p < r) { int q = partition(A, p, r); quicksort(A, p, q - 1); quicksort(A, q + 1, r); } } int getNumberOfCoin(int C[], int n, int m) { int T[50000]; for (int j = 0; j <= n; j++) { T[j] = INF; } T[0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j <= n; j++) { if (j - C[i] >= 0) { T[j] = min(T[j], T[j - C[i]] + 1); } } } return T[n]; } int knapsack(int w, int n, int *v, int *ww) { int W[101][10001]; for (int j = 0; j <= w; j++) { W[0][j] = 0; } for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { for (int j = 0; j <= w; j++) { if (j - ww[k] < 0) { W[i + 1][j] = W[i][j]; } if (j - ww[i] >= 0) { W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]); } } } } return W[n][w]; } int fib(int n) { vector<int> v(n + 1); v[0] = 1; v[1] = 1; for (int i = 2; i < n + 1; i++) { v[i] = v[i - 2] + v[i - 1]; } return v[n]; } int main() { map<string, vector<int>> dic; string voc; int page; while (cin >> voc >> page) { dic[voc].push_back(page); } map<string, vector<int>>::iterator it = dic.begin(); while (it != dic.end()) { cout << (*it).first << endl; sort((*it).second.begin(), (*it).second.end()); for (int i = 0; i < (*it).second.size(); i++) { if (i == (*it).second.size() - 1) { cout << (*it).second[i]; } else cout << (*it).second[i] << " "; } cout << endl; it++; } } int isPrime(int x) { if (x <= 1) return false; if (x > 2 && x % 2 == 0) return false; for (int i = 2; i <= sqrt(x); i++) { if (x % i == 0) { return false; } } if (x == 2) return true; return true; }
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
1,143
2
#include <bits/stdc++.h> using namespace std; pair<string, int> a[100]; int main() { int t = 0, g; string f; while (cin >> a[t].first >> a[t].second) t++; sort(a, a + t); cout << a[0].first << endl << a[0].second; for (int i = 1; i < t; i++) { bool n; f = a[i].first, g = a[i].second; if (i) if (f == a[i - 1].first) n = 1; if (n) cout << " " << g; else cout << endl << f << endl << g; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; pair<string, int> a[100]; int main() { int t = 0, g; string f; while (cin >> a[t].first >> a[t].second) t++; sort(a, a + t); cout << a[0].first << endl << a[0].second; for (int i = 1; i < t; i++) { bool n = 0; f = a[i].first, g = a[i].second; if (i) if (f == a[i - 1].first) n = 1; if (n) cout << " " << g; else cout << endl << f << endl << g; } cout << endl; return 0; }
[["+", 0, 7, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
1
169
25
#define scanf_s scanf //#define sscanf_s sscanf //#define gets_s gets #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; #define MAX 1001 #define _MAX 100 #define HO 6 int main(void) { char str[MAX]; string word[_MAX]; int pa[_MAX], rank[_MAX], cou, a; for (cou = 0; scanf_s("%s %d", str, MAX, &pa[cou]) != EOF; ++cou) { string wo(str); word[cou] = wo; rank[cou] = cou; } for (int i = 0; i < cou; ++i) { for (int j = cou - 1; j > i; --j) { if (word[rank[j]] <= word[rank[j - 1]]) { if (word[rank[j]] == word[rank[j - 1]]) { if (pa[rank[j]] < pa[rank[j - 1]]) { a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a; } } else { a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a; } } } } for (int i = 0; i < cou; ++i) { if (i == 0 || word[rank[i - 1]] != word[rank[i]]) cout << word[rank[i]] << "\n"; if (i != 0 && word[rank[i - 1]] == word[rank[i]]) printf(" "); printf("%d", pa[rank[i]]); if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]]) printf("\n"); } printf("\n"); }
#define scanf_s scanf //#define sscanf_s sscanf //#define gets_s gets #include <iostream> #include <math.h> #include <stdio.h> #include <string> using namespace std; #define MAX 1001 #define _MAX 100 #define HO 6 int main(void) { char str[MAX]; string word[_MAX]; int pa[_MAX], rank[_MAX], cou, a; for (cou = 0; scanf_s("%s %d", str, &pa[cou]) != EOF; ++cou) { string wo(str); word[cou] = wo; rank[cou] = cou; } for (int i = 0; i < cou; ++i) { for (int j = cou - 1; j > i; --j) { if (word[rank[j]] <= word[rank[j - 1]]) { if (word[rank[j]] == word[rank[j - 1]]) { if (pa[rank[j]] < pa[rank[j - 1]]) { a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a; } } else { a = rank[j]; rank[j] = rank[j - 1]; rank[j - 1] = a; } } } } for (int i = 0; i < cou; ++i) { if (i == 0 || word[rank[i - 1]] != word[rank[i]]) cout << word[rank[i]] << "\n"; if (i != 0 && word[rank[i - 1]] == word[rank[i]]) printf(" "); printf("%d", pa[rank[i]]); if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]]) printf("\n"); } printf("\n"); }
[["-", 0, 7, 15, 16, 31, 2, 3, 4, 0, 22], ["-", 0, 7, 15, 16, 31, 2, 3, 4, 0, 21]]
1
409
2
#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; //#define int long long #define DBG 1 #define dump(o) \ if (DBG) { \ cerr << #o << " " << o << endl; \ } #define dumpc(o) \ if (DBG) { \ cerr << #o; \ for (auto &e : (o)) \ cerr << " " << e; \ cerr << endl; \ } #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++) #define all(c) c.begin(), c.end() const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9 + 7); signed main() { map<string, vector<int>> M; string s; int n; while (cin >> s >> n) { M[s].push_back(n); } each(it, M) { cout << it->first << endl; sort(it->second.begin(), it->second.end()); int i(0); each(that, it->second) { if (i) cout << " "; cout << *that; } cout << endl; } return 0; }
#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; //#define int long long #define DBG 1 #define dump(o) \ if (DBG) { \ cerr << #o << " " << o << endl; \ } #define dumpc(o) \ if (DBG) { \ cerr << #o; \ for (auto &e : (o)) \ cerr << " " << e; \ cerr << endl; \ } #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++) #define all(c) c.begin(), c.end() const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9 + 7); signed main() { map<string, vector<int>> M; string s; int n; while (cin >> s >> n) { M[s].push_back(n); } each(it, M) { cout << it->first << endl; sort(it->second.begin(), it->second.end()); int i(0); each(that, it->second) { if (i++) cout << " "; cout << *that; } cout << endl; } return 0; }
[["+", 0, 9, 0, 57, 15, 339, 51, 27, 17, 29]]
1
211
1
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define all(in) in.begin(), in.end() #define MAX 9999999 using namespace std; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; int main() { string temp; map<string, vi> mp; while (cin >> temp) { int n; cin >> n; mp[temp].push_back(n); sort(all(mp[temp])); } for (auto itr = mp.begin(); itr != mp.end(); itr++) { cout << itr->first << " "; rep(i, mp[itr->first].size()) { if (i) cout << " "; cout << mp[itr->first][i]; } cout << endl; } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define all(in) in.begin(), in.end() #define MAX 9999999 using namespace std; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; int main() { string temp; map<string, vi> mp; while (cin >> temp) { int n; cin >> n; mp[temp].push_back(n); sort(all(mp[temp])); } for (auto itr = mp.begin(); itr != mp.end(); itr++) { cout << itr->first << endl; rep(i, mp[itr->first].size()) { if (i) cout << " "; cout << mp[itr->first][i]; } cout << endl; } }
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
246
4
#include <algorithm> #include <iostream> #include <map> #include <vector> int main() { std::string s; int p; std::map<std::string, std::vector<int>> m; while (std::cin >> s >> p, !std::cin.eof()) { m[s].push_back(p); } std::map<std::string, std::vector<int>>::iterator m_it = m.begin(); while (m_it != m.end()) { std::cout << (*m_it).first << std::endl; std::sort((*m_it).second.begin(), (*m_it).second.end()); std::vector<int>::iterator v_it = (*m_it).second.begin(); while (v_it != (*m_it).second.end()) { std::cout << *v_it; v_it++; (v_it != (*m_it).second.end()) ? std::cout << std::endl : std::cout << " "; } m_it++; } return 0; } /* Sample Input style 12 even 25 introduction 3 easy 9 style 7 document 13 style 21 even 18 Output for the Sample Input document 13 easy 9 even 18 25 introduction 3 style 7 12 21 */
#include <algorithm> #include <iostream> #include <map> #include <vector> int main() { std::string s; int p; std::map<std::string, std::vector<int>> m; while (std::cin >> s >> p, !std::cin.eof()) { m[s].push_back(p); } std::map<std::string, std::vector<int>>::iterator m_it = m.begin(); while (m_it != m.end()) { std::cout << (*m_it).first << std::endl; std::sort((*m_it).second.begin(), (*m_it).second.end()); std::vector<int>::iterator v_it = (*m_it).second.begin(); while (v_it != (*m_it).second.end()) { std::cout << *v_it; v_it++; (v_it == (*m_it).second.end()) ? std::cout << std::endl : std::cout << " "; } m_it++; } return 0; } /* Sample Input style 12 even 25 introduction 3 easy 9 style 7 document 13 style 21 even 18 Output for the Sample Input document 13 easy 9 even 18 25 introduction 3 style 7 12 21 */
[["-", 0, 1, 0, 41, 15, 23, 0, 16, 17, 79], ["+", 0, 1, 0, 41, 15, 23, 0, 16, 17, 60]]
1
235
2
#include <algorithm> #include <iostream> #include <list> #include <map> #include <string> #include <vector> using namespace std; int main() { string strInput; map<string, vector<int>> index; int intInput = 0; while (cin >> strInput >> intInput) { index[strInput].push_back(intInput); } for (map<string, vector<int>>::iterator it = index.begin(); it != index.end(); it++) { sort(index[(*it).first].begin(), index[(*it).first].end()); cout << (*it).first << endl; for (int i = 0; i < index[(*it).first].size(); i++) { if (i == index[(*it).first].size() - 1) { cout << index[(*it).first][i]; } cout << index[(*it).first][i] << ' '; } cout << endl; } return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <string> #include <vector> using namespace std; int main() { string strInput; map<string, vector<int>> index; int intInput = 0; while (cin >> strInput >> intInput) { index[strInput].push_back(intInput); } for (map<string, vector<int>>::iterator it = index.begin(); it != index.end(); it++) { sort(index[(*it).first].begin(), index[(*it).first].end()); cout << (*it).first << endl; for (int i = 0; i < index[(*it).first].size(); i++) { if (i == index[(*it).first].size() - 1) { cout << index[(*it).first][i]; break; } cout << index[(*it).first][i] << ' '; } cout << endl; } return 0; }
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
1
228
2
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { map<string, vector<int>> in; string goku; int id; while (cin >> goku >> id) { in[goku].push_back(id); } for (map<string, vector<int>>::iterator it = in.begin(); it != in.end(); it++) { cout << (*it).first << " "; vector<int> &go = (*it).second; sort(go.begin(), go.end()); for (vector<int>::iterator it_p = go.begin(); it_p != go.end(); it_p++) { cout << (*it_p); if (it_p + 1 != go.end()) cout << " "; } cout << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { map<string, vector<int>> in; string goku; int id; while (cin >> goku >> id) { in[goku].push_back(id); } for (map<string, vector<int>>::iterator it = in.begin(); it != in.end(); it++) { cout << (*it).first << endl; vector<int> &go = (*it).second; sort(go.begin(), go.end()); for (vector<int>::iterator it_p = go.begin(); it_p != go.end(); it_p++) { cout << (*it_p); if (it_p + 1 != go.end()) cout << " "; } cout << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 62], ["-", 8, 9, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
192
4
data_hash = Hash.new([]) while data = gets do if data == nil break end word, page = data.chomp.split data_hash[word] += [page.to_i] end data_hash.sort.each do |word, page| puts word puts page.sort end
data_hash = Hash.new([]) while data = gets do if data == nil break end word, page = data.chomp.split data_hash[word] += [page.to_i] end data_hash.sort.each do |word, page| puts word puts page.sort.join(' ') end
[["+", 8, 736, 0, 652, 3, 4, 0, 652, 17, 131], ["+", 8, 736, 0, 652, 3, 4, 0, 652, 735, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 62], ["+", 3, 4, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
4
58
7
hash = {} while gets != nil word, page = gets.split if hash[word] == nil hash[word] = [page.to_i] else hash[word] << page.to_i end end hash.values.each {|item| item.sort!} hash = Hash[hash.sort] hash.each {|k, v| puts k, v.join(" ")}
hash = {} while (str = gets) != nil word, page = str.split if hash[word] == nil hash[word] = [page.to_i] else hash[word] << page.to_i end end hash.values.each {|item| item.sort!} hash = Hash[hash.sort] hash.each {|k, v| puts k, v.join(" ")}
[["+", 0, 493, 0, 89, 15, 738, 31, 739, 0, 24], ["+", 0, 89, 15, 738, 31, 739, 0, 662, 31, 22], ["+", 0, 89, 15, 738, 31, 739, 0, 662, 0, 32], ["+", 0, 493, 0, 89, 15, 738, 31, 739, 0, 25], ["-", 0, 89, 8, 170, 0, 662, 12, 652, 486, 22], ["+", 0, 89, 8, 170, 0, 662, 12, 652, 486, 22]]
4
85
6
hash = Hash.new {|hash, key| hash[key] = []} while (str = gets) != nil word, page = gets.split hash[word] << page.to_i end hash.values.each {|item| item.sort!} hash = Hash[hash.sort] hash.each {|k, v| puts k, v.join(" ")}
hash = Hash.new {|hash, key| hash[key] = []} while (str = gets) != nil word, page = str.split hash[word] << page.to_i end hash.values.each {|item| item.sort!} hash = Hash[hash.sort] hash.each {|k, v| puts k, v.join(" ")}
[["-", 0, 89, 8, 170, 0, 662, 12, 652, 486, 22], ["+", 0, 89, 8, 170, 0, 662, 12, 652, 486, 22]]
4
85
2
index=Hash.new{|word,page| word[page] = []} while line =gets do word,page= line.split(" ") page =page.to_i index[word]<<page end p index index.each{|word,page|page.sort!} index2=index.sort index2.each{|key,value| puts key puts value.join(" ") }
index=Hash.new{|word,page| word[page] = []} while line =gets do word,page= line.split(" ") page =page.to_i index[word]<<page end index.each{|word,page|page.sort!} index2=index.sort index2.each{|key,value| puts key puts value.join(" ") }
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 36, 36, 0, 493, 0, 652, 3, 4, 0, 22]]
4
89
2
cat rb.rb hash = Hash.new([]) while true do line = gets break if line == nil line.chomp word, page = line.split(' ') hash[word] += [page.to_i] end arr = hash.sort arr.each do |w| puts w[0] w[1].sort! puts w[1].join(' ') end
hash = Hash.new([]) while true do line = gets break if line == nil line.chomp word, page = line.split(' ') hash[word] += [page.to_i] end arr = hash.sort arr.each do |w| puts w[0] w[1].sort! puts w[1].join(' ') end
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["-", 0, 493, 0, 652, 3, 4, 0, 652, 486, 22], ["-", 0, 493, 0, 652, 3, 4, 0, 652, 17, 131], ["-", 0, 493, 0, 652, 3, 4, 0, 652, 735, 22]]
4
86
4
dic = {} while True: try: word,PageNum = input().split() if word not in dic: dic[word] = [] dic[word].append(PageNum) else: dic[word].append(PageNum) except: break for k,v in sorted(dic.items()): print(k) print(" ".join(map(str,sorted(v))))
dic = {} while True: try: word,PageNum = input().split() if word not in dic: dic[word] = [] dic[word].append(int(PageNum)) else: dic[word].append(int(PageNum)) except: break for k,v in sorted(dic.items()): print(k) print(" ".join(map(str,sorted(v))))
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
93
6
dic = {} while True: try: word, pgn = input().split() if word in dic.keys(): dic[word].append(int(pgn)) else: dic[word] = [int(pgn)] except: break for k, v in dic.items(): print(k) print(' '.join(map(str, sorted(v))))
dic = {} while True: try: word, pgn = input().split() if word in dic.keys(): dic[word].append(int(pgn)) else: dic[word] = [int(pgn)] except: break for k, v in sorted(dic.items()): print(k) print(' '.join(map(str, sorted(v))))
[["+", 36, 36, 0, 656, 0, 7, 12, 652, 63, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
91
3
index = {} while True: try: w, p = list(map(str, input().split())) index.setdefault(w,[]).append(int(p)) except: break for k,v in sorted(index.items()): print(k) print(" ".join(map(str, v)))
index = {} while True: try: w, p = list(map(str, input().split())) index.setdefault(w,[]).append(int(p)) except: break for k,v in sorted(index.items()): print(k) print(" ".join(map(str, sorted(v))))
[["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
82
3
function main() { function howMuch(gram) { var i, j, w, g, c, p, min, _pat, pat = [ [ 0, [] ] ]; for (i = 0; i < 3; i++) { w = [ 200, 300, 500 ][i]; _pat = []; while (p = pat.shift()) { g = p[0]; c = p[1]; for (j = 0; j * w + g <= gram; j++) { _pat.push([ j * w + g, c.concat(j) ]); } _pat.push([ j * w + g, c.concat(j) ]); } pat = _pat; // console.log(pat); } pat = _pat; // console.log(pat); min = Infinity; while (p = pat.shift()) { g = p[0]; if (g < gram) continue; c = p[1]; p = ((c[0] % 5) * 380) + (~~(c[0] / 5) * 5 * (380 * 0.8)) + ((c[1] % 4) * 550) + (~~(c[1] / 4) * 4 * (550 * 0.85)) + ((c[2] % 3) * 850) + (~~(c[2] / 3) * 3 * (850 * 0.88)); min = p < min ? p : min; } return min; } var end = false; input.forEach(function(line) { if (line.trim() == '' || end) return; if (line == 0) { end = true; return; } console.log(howMuch(parseInt(line, 10))); }); } var input = ''; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { input += chunk; }); process.stdin.on('end', function() { input = input.split('\n'); main(); });
function main() { function howMuch(gram) { var i, j, w, g, c, p, min, _pat, pat = [ [ 0, [] ] ]; for (i = 0; i < 3; i++) { w = [ 200, 300, 500 ][i]; _pat = []; while (p = pat.shift()) { g = p[0]; c = p[1]; for (j = 0; j * w + g <= gram; j++) { _pat.push([ j * w + g, c.concat(j) ]); } _pat.push([ j * w + g, c.concat(j) ]); } pat = _pat; // console.log(pat); } pat = _pat; // console.log(pat); min = Infinity; while (p = pat.shift()) { g = p[0]; if (g !== gram) continue; c = p[1]; p = ((c[0] % 5) * 380) + (~~(c[0] / 5) * 5 * (380 * 0.8)) + ((c[1] % 4) * 550) + (~~(c[1] / 4) * 4 * (550 * 0.85)) + ((c[2] % 3) * 850) + (~~(c[2] / 3) * 3 * (850 * 0.88)); min = p < min ? p : min; } return min; } var end = false; input.forEach(function(line) { if (line.trim() == '' || end) return; if (line == 0) { end = true; return; } console.log(howMuch(parseInt(line, 10))); }); } var input = ''; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { input += chunk; }); process.stdin.on('end', function() { input = input.split('\n'); main(); });
[["-", 8, 556, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 8, 556, 0, 57, 15, 23, 0, 16, 17, 566]]
2
464
2
import java.util.Scanner; // Discounts of Buckwheat public class Main { static int[] m = {200, 300, 500}; static int[] p = {380, 550, 850}; static int[] d = {5, 4, 3}; static double[] r = {0.8, 0.85, 0.88}; static int min; static void dfs(int k, int rest, double x) { if (rest <= 0) { min = (int)Math.min(min, x); return; } if (k == 3) return; for (int i = 0; i <= 40; i++) { dfs(k + 1, rest - m[k] * i, x + p[k] * (i - i % d[k]) * r[k] + p[k] * (i % d[k])); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; min = Integer.MAX_VALUE; dfs(0, n, 0); System.out.println(min); } } }
import java.util.Scanner; // Discounts of Buckwheat public class Main { static int[] m = {200, 300, 500}; static int[] p = {380, 550, 850}; static int[] d = {5, 4, 3}; static double[] r = {0.8, 0.85, 0.88}; static int min; static void dfs(int k, int rest, double x) { if (rest == 0) { min = (int)Math.min(min, x); return; } if (k == 3 || rest < 0) return; for (int i = 0; i <= 40; i++) { dfs(k + 1, rest - m[k] * i, x + p[k] * (i - i % d[k]) * r[k] + p[k] * (i % d[k])); } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; min = Integer.MAX_VALUE; dfs(0, n, 0); System.out.println(min); } } }
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 106], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 15, 0, 16, 12, 16, 12, 499]]
3
259
6
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n; int min; while (true) { n = sc.nextInt(); if (n == 0) { break; } min = Integer.MAX_VALUE; for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { for (int k = 0; k < 100; k++) { if (n <= i * 200 + j * 300 + k * 500) { int sum = 0; sum += i * 380; sum -= (i / 5) * 380 * 5 * 0.20; sum += j * 550; sum -= (j / 4) * 550 * 4 * 0.15; sum += k * 850; sum -= (k / 3) * 850 * 3 * 0.12; if (sum < min) { min = sum; } } } } } System.out.println(min); } } }
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n; int min; while (true) { n = sc.nextInt(); if (n == 0) { break; } min = Integer.MAX_VALUE; for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { for (int k = 0; k < 100; k++) { if (n == i * 200 + j * 300 + k * 500) { int sum = 0; sum += i * 380; sum -= (i / 5) * 380 * 5 * 0.20; sum += j * 550; sum -= (j / 4) * 550 * 4 * 0.15; sum += k * 850; sum -= (k / 3) * 850 * 3 * 0.12; if (sum < min) { min = sum; } } } } } System.out.println(min); } } }
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 17, 60]]
3
223
2
a[6] = {2, 3, 5, 10, 12, 15}, b[6] = {380, 550, 850, 1520, 1870, 2244}, m[51]; main(n, d, T) { for (n = 2; n < 51; n++) for (m[n] = 9999, d = 5; ~d; d--) if (a[d] <= n && m[n] > (T = m[n - a[d]] + b[d])) m[n] = T; for (; scanf("%d", &n), n;) printf("%d\n", m[n / 100]); exit(0); }
a[] = {2, 3, 5, 10, 12, 15}, b[] = {380, 550, 850, 1520, 1870, 2244}, m[51]; main(n, d, T) { for (n = 1; n < 51; n++) for (m[n] = 9999, d = 5; ~d; d--) if (a[d] <= n && m[n] > (T = m[n - a[d]] + b[d])) m[n] = T; for (; scanf("%d", &n), n;) printf("%d\n", m[n / 100]); exit(0); }
[["-", 36, 36, 0, 30, 0, 42, 0, 69, 71, 13], ["+", 0, 30, 0, 42, 0, 69, 0, 70, 0, 22], ["-", 12, 34, 12, 34, 31, 11, 31, 69, 71, 13], ["+", 12, 34, 31, 11, 31, 69, 0, 70, 0, 22], ["-", 0, 9, 0, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 9, 0, 9, 0, 7, 10, 11, 12, 13]]
0
163
27
#include <stdio.h> #define A_MAX 25 // A店25*200=5000 #define B_MAX 16 // B店16*300=4800 #define C_MAX 10 // C店10*500=5000 #define A_PRICE 380 // A店のそば粉1袋の金額 #define B_PRICE 550 // B店のそば粉1袋の金額 #define C_PRICE 850 // C店のそば粉1袋の金額 #define A_QUANT 200 // A店の1袋辺りの内容量 #define B_QUANT 300 // B店の1袋辺りの内容量 #define C_QUANT 500 // C店の1袋辺りの内容量 void simulation(int input, int *result); //購入金額をシミュレートする関数 main() { int n = 0, result = 0; while (scanf("%d", &n), n != 0) { simulation(n, &result); printf("%d\n", result); } return 0; } void simulation(int input, int *result) { int a = 0, b = 0, c = 0; //制御変数 int price = 0; //価格を代入する変数 int a_low = 0, a_high = 0; // a_low:割引される袋数,a_high:割引されない袋数 int b_low = 0, b_high = 0; // b_low:割引される袋数,b_high:割引されない袋数 int c_low = 0, c_high = 0; // c_low:割引される袋数,c_high:割引されない袋数 for (a = 0; a <= A_MAX; a++) { for (b = 0; b <= B_MAX; b++) { for (c = 0; c <= C_MAX; c++) { if (((a * A_QUANT) + (b * B_QUANT) + (c * C_QUANT)) == input) { a_high = a % 5, a_low = a - a_high; b_high = b % 4, b_low = b - b_high; c_high = c % 3, c_low = c - c_high; price = (((A_PRICE * a_low) * 0.8) + (A_PRICE * a_high)) + (((B_PRICE * b_low) * 0.85) + (B_PRICE * b_high)) + (((C_PRICE * c_low) * 0.88) + (C_PRICE * c_high)); if (*result == 0) { *result = price; } if (*result > price) { *result = price; } } } } } }
#include <stdio.h> #define A_MAX 25 // A店25*200=5000 #define B_MAX 16 // B店16*300=4800 #define C_MAX 10 // C店10*500=5000 #define A_PRICE 380 // A店のそば粉1袋の金額 #define B_PRICE 550 // B店のそば粉1袋の金額 #define C_PRICE 850 // C店のそば粉1袋の金額 #define A_QUANT 200 // A店の1袋辺りの内容量 #define B_QUANT 300 // B店の1袋辺りの内容量 #define C_QUANT 500 // C店の1袋辺りの内容量 void simulation(int input, int *result); //購入金額をシミュレートする関数 main() { int n = 0, result = 0; while (scanf("%d", &n), n != 0) { simulation(n, &result); printf("%d\n", result); result = 0; } return 0; } void simulation(int input, int *result) { int a = 0, b = 0, c = 0; //制御変数 int price = 0; //価格を代入する変数 int a_low = 0, a_high = 0; // a_low:割引される袋数,a_high:割引されない袋数 int b_low = 0, b_high = 0; // b_low:割引される袋数,b_high:割引されない袋数 int c_low = 0, c_high = 0; // c_low:割引される袋数,c_high:割引されない袋数 for (a = 0; a <= A_MAX; a++) { for (b = 0; b <= B_MAX; b++) { for (c = 0; c <= C_MAX; c++) { if (((a * A_QUANT) + (b * B_QUANT) + (c * C_QUANT)) == input) { // printf("a = %d b = %d c = %d\n", a, b, c); a_high = a % 5, a_low = a - a_high; b_high = b % 4, b_low = b - b_high; c_high = c % 3, c_low = c - c_high; price = (((A_PRICE * a_low) * 0.8) + (A_PRICE * a_high)) + (((B_PRICE * b_low) * 0.85) + (B_PRICE * b_high)) + (((C_PRICE * c_low) * 0.88) + (C_PRICE * c_high)); // printf("price = %d\n", price); if (*result == 0) { *result = price; } if (*result > price) { *result = price; } } } } } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
348
4
#include <iostream> using namespace std; int w; main() { while (cin >> w, w) { int ans = 1e9; w /= 100; for (int i = 0; i < 51; i++) for (int j = 0; j < 51; j++) for (int k = 0; k < 51; k++) { if (i * 2 + j * 3 + k * 5 < w) continue; int now = i / 5 * 5 * 38 * 8 + i % 5 * 380 + j / 4 * 2 * 55 * 17 + j % 4 * 550 + k / 3 * 3 * 748 + k % 3 * 850; ans = ans < now ? ans : now; } cout << ans << endl; } }
#include <iostream> using namespace std; int w; main() { while (cin >> w, w) { int ans = 1e9; w /= 100; for (int i = 0; i < 51; i++) for (int j = 0; j < 51; j++) for (int k = 0; k < 51; k++) { if (i * 2 + j * 3 + k * 5 != w) continue; int now = i / 5 * 5 * 38 * 8 + i % 5 * 380 + j / 4 * 2 * 55 * 17 + j % 4 * 550 + k / 3 * 3 * 748 + k % 3 * 850; ans = ans < now ? ans : now; } cout << ans << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79]]
1
160
2
#include <bits/stdc++.h> using namespace std; int main() { int n; int bw[][2] = {{2, 380}, {3, 550}, {5, 850}, {10, 1520}, {12, 1870}, {15, 2244}}; int dp[51] = {0}; for (int i = 0; i < 51; ++i) { dp[i] = 1e+9; } for (int i = 0; i < 51; ++i) { for (int j = 0; j < 6; ++j) { if (i >= bw[j][0]) { dp[i] = min(dp[i], dp[i - bw[j][0]] + bw[j][1]); // dp[i]=((dp[iSize-jSize]+jValue < dp[i]) // ? dp[iSize-jSize]+jValue : dp[i]); } } } while (cin >> n, n) { cout << dp[n / 100] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int bw[][2] = {{2, 380}, {3, 550}, {5, 850}, {10, 1520}, {12, 1870}, {15, 2244}}; int dp[51] = {0}; for (int i = 1; i < 51; ++i) { dp[i] = 1e+9; } for (int i = 0; i < 51; ++i) { for (int j = 0; j < 6; ++j) { if (i >= bw[j][0]) { dp[i] = min(dp[i], dp[i - bw[j][0]] + bw[j][1]); // dp[i]=((dp[iSize-jSize]+jValue < dp[i]) // ? dp[iSize-jSize]+jValue : dp[i]); } } } while (cin >> n, n) { cout << dp[n / 100] << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
200
2
#include <bits/stdc++.h> using namespace std; /* template {{{ */ /* vim: set foldmethod=marker: */ /* Roadagain {{{ */ /****************************************************************************************/ /* */ /* */ /* */ /* /####### /## /## */ /* | ##__ ## | ## |__/ */ /* | ## \ ## /###### /###### /####### /###### /###### /###### /## * /####### */ /* | #######/ /##__ ## |____ ## /##__ ## |____ ## /##__ ## |____ ##| ##| * ##__ ## */ /* | ##__ ##| ## \ ## /#######| ## | ## /#######| ## \ ## /#######| ##| * ## \ ## */ /* | ## \ ##| ## | ## /##__ ##| ## | ## /##__ ##| ## | ## /##__ ##| ##| * ## | ## */ /* | ## | ##| ######/| #######| #######| #######| #######| #######| ##| * ## | ## */ /* |__/ |__/ \______/ \_______/ \_______/ \_______/ \____ ## * \_______/|__/|__/ |__/ */ /* /## \ ## */ /* | ######/ */ /* \______/ */ /* */ /****************************************************************************************/ /* }}} */ /* constant {{{ */ const int INF = (int)1e9; const int MOD = (int)1e9 + 7; const double PI = acos(-1); const double EPS = 1e-14; /* }}} */ /* alias {{{ */ template <class T> using vec = vector<T>; using ll = long long; using ull = unsigned long long; using vi = vec<int>; using vl = vec<ll>; using vd = vec<double>; using pii = pair<int, int>; using pdd = pair<double, double>; using vec2 = complex<double>; /* }}} */ /* repetition {{{ */ #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define RFOR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define REPIT(i, obj) for (auto i = (obj).begin(); i != (obj).end(); ++i) #define RREPIT(i, obj) for (auto i = (obj).rbegin(); i != (obj).rend(); ++i) /* }}} */ /* short {{{ */ #define pb emplace_back #define mp make_pair #define fst first #define sec second /* }}} */ /* input {{{ */ template <class T = int> inline T in() { T x; cin >> x; return x; } template <class T = int> inline vec<T> in(int n) { vec<T> v(n); REP(i, n) v[i] = in<T>(); return v; } template <class T = int> inline void in(T *x, int n) { REP(i, n) x[i] = in<T>(); } #define inl in<ll> #define ind in<double> #define ins in<string> /* }}} */ /* container util {{{ */ #define ALL(obj) (obj).begin(), (obj).end() #define ALLA(ary, n) (ary), ((ary) + (n)) #define RALL(obj) (obj).rbegin(), (obj).rend() #define SZ(obj) (obj).size() #define SZA(ary) (sizeof(ary) / sizeof(*ary)) #define SORT(obj) sort(ALL(obj)) #define SORTA(ary, n) sort(ALLA(ary, n)) #define EXIST(obj, key) ((obj).find(key) != (obj).end()) #define CLEARY(ary) memset((ary), 0, sizeof(ary)) /* }}} */ /* print util {{{ */ template <class T> inline void print(const T &x) { cout << x << '\n'; } template <class T> inline void printd(const T &x, int d) { cout << fixed << setprecision(d) << x << '\n'; } template <class T> inline void printv(vec<T> &v) { int n = sz(v); REP(i, n) cout << v[i] << "\n "[i < n - 1]; } template <class T> inline void printv(vec<T> &v, int n) { REP(i, n) cout << v[i] << "\n "[i < n - 1]; } template <class T> inline void printa(T *ary, int n) { REP(i, n) cout << ary[i] << "\n "[i < n - 1]; } #define DUMP(x) cerr << #x << ": " << (x) << '\n' #define DEBUG(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << '\n' /* }}} */ /* template }}} */ const pii price[] = {{2, 380}, {3, 550}, {5, 850}, {10, 1520}, {12, 1870}, {15, 2244}}; signed main() { int w; while (w = in(), w) { int dp[64]; fill(dp, dp + 64, INF); dp[0] = 0; w /= 100; for (auto &i : price) { RFOR(j, 0, w - i.fst + 1) { dp[j + i.fst] = min(dp[j + i.fst], dp[j] + i.sec); } } print(dp[w]); } return 0; }
#include <bits/stdc++.h> using namespace std; /* template {{{ */ /* vim: set foldmethod=marker: */ /* Roadagain {{{ */ /****************************************************************************************/ /* */ /* */ /* */ /* /####### /## /## */ /* | ##__ ## | ## |__/ */ /* | ## \ ## /###### /###### /####### /###### /###### /###### /## * /####### */ /* | #######/ /##__ ## |____ ## /##__ ## |____ ## /##__ ## |____ ##| ##| * ##__ ## */ /* | ##__ ##| ## \ ## /#######| ## | ## /#######| ## \ ## /#######| ##| * ## \ ## */ /* | ## \ ##| ## | ## /##__ ##| ## | ## /##__ ##| ## | ## /##__ ##| ##| * ## | ## */ /* | ## | ##| ######/| #######| #######| #######| #######| #######| ##| * ## | ## */ /* |__/ |__/ \______/ \_______/ \_______/ \_______/ \____ ## * \_______/|__/|__/ |__/ */ /* /## \ ## */ /* | ######/ */ /* \______/ */ /* */ /****************************************************************************************/ /* }}} */ /* constant {{{ */ const int INF = (int)1e9; const int MOD = (int)1e9 + 7; const double PI = acos(-1); const double EPS = 1e-14; /* }}} */ /* alias {{{ */ template <class T> using vec = vector<T>; using ll = long long; using ull = unsigned long long; using vi = vec<int>; using vl = vec<ll>; using vd = vec<double>; using pii = pair<int, int>; using pdd = pair<double, double>; using vec2 = complex<double>; /* }}} */ /* repetition {{{ */ #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define RFOR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define REPIT(i, obj) for (auto i = (obj).begin(); i != (obj).end(); ++i) #define RREPIT(i, obj) for (auto i = (obj).rbegin(); i != (obj).rend(); ++i) /* }}} */ /* short {{{ */ #define pb emplace_back #define mp make_pair #define fst first #define sec second /* }}} */ /* input {{{ */ template <class T = int> inline T in() { T x; cin >> x; return x; } template <class T = int> inline vec<T> in(int n) { vec<T> v(n); REP(i, n) v[i] = in<T>(); return v; } template <class T = int> inline void in(T *x, int n) { REP(i, n) x[i] = in<T>(); } #define inl in<ll> #define ind in<double> #define ins in<string> /* }}} */ /* container util {{{ */ #define ALL(obj) (obj).begin(), (obj).end() #define ALLA(ary, n) (ary), ((ary) + (n)) #define RALL(obj) (obj).rbegin(), (obj).rend() #define SZ(obj) (obj).size() #define SZA(ary) (sizeof(ary) / sizeof(*ary)) #define SORT(obj) sort(ALL(obj)) #define SORTA(ary, n) sort(ALLA(ary, n)) #define EXIST(obj, key) ((obj).find(key) != (obj).end()) #define CLEARY(ary) memset((ary), 0, sizeof(ary)) /* }}} */ /* print util {{{ */ template <class T> inline void print(const T &x) { cout << x << '\n'; } template <class T> inline void printd(const T &x, int d) { cout << fixed << setprecision(d) << x << '\n'; } template <class T> inline void printv(vec<T> &v) { int n = sz(v); REP(i, n) cout << v[i] << "\n "[i < n - 1]; } template <class T> inline void printv(vec<T> &v, int n) { REP(i, n) cout << v[i] << "\n "[i < n - 1]; } template <class T> inline void printa(T *ary, int n) { REP(i, n) cout << ary[i] << "\n "[i < n - 1]; } #define DUMP(x) cerr << #x << ": " << (x) << '\n' #define DEBUG(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << '\n' /* }}} */ /* template }}} */ const pii price[] = {{2, 380}, {3, 550}, {5, 850}, {10, 1520}, {12, 1870}, {15, 2244}}; signed main() { int w; while (w = in(), w) { int dp[64]; fill(dp, dp + 64, INF); dp[0] = 0; w /= 100; for (auto &i : price) { REP(j, w - i.fst + 1) { dp[j + i.fst] = min(dp[j + i.fst], dp[j] + i.sec); } } print(dp[w]); } return 0; }
[["-", 0, 338, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 338, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
770
4
#include <iostream> using namespace std; //????????? #define AG 200 #define BG 300 #define CG 500 //????????? #define AM 380 #define BM 550 #define CM 850 //?????????????????? #define AN 5 #define BN 4 #define CN 3 //?????????????????? #define AP 20 #define BP 15 #define CP 12 int main() { int g; int a, b, c; int total; int money, work; while (1) { cin >> g; if (g == 0) { break; } a = 0; b = 0; c = 0; total = 0; money = 0; for (c = 0; c * CG <= g; c++) { for (b = 0; c * CG + b * BG <= g; b++) { total = c * CG + b * BG; a = (g - total) / 200; total += a * AG; if (total != g) { continue; } //???????¨???? work = (a / AN) * AN * AM * (100 - AP) / 100 + (a % AN) * AM + (b / BN) * BN * BM * (100 - BP) / 100 + (b % BN) * BM + (c / CN) * CN * CM * (100 - CP) / 100 + (c % CN) * CM; if (money < work) { money = work; } } } cout << money << endl; } return 0; }
#include <iostream> using namespace std; //????????? #define AG 200 #define BG 300 #define CG 500 //????????? #define AM 380 #define BM 550 #define CM 850 //?????????????????? #define AN 5 #define BN 4 #define CN 3 //?????????????????? #define AP 20 #define BP 15 #define CP 12 int main() { int g; int a, b, c; int total; int money, work; while (1) { cin >> g; if (g == 0) { break; } a = 0; b = 0; c = 0; total = 0; money = 0; for (c = 0; c * CG <= g; c++) { for (b = 0; c * CG + b * BG <= g; b++) { total = c * CG + b * BG; a = (g - total) / 200; total += a * AG; if (total != g) { continue; } //???????¨???? work = (a / AN) * AN * AM * (100 - AP) / 100 + (a % AN) * AM + (b / BN) * BN * BM * (100 - BP) / 100 + (b % BN) * BM + (c / CN) * CN * CM * (100 - CP) / 100 + (c % CN) * CM; if (money == 0 || money > work) { money = work; } } } cout << money << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47]]
1
286
6
#include <algorithm> #include <stdio.h> using namespace std; int n, ret; int main() { while (true) { scanf("%d", &n); if (n == 0) break; ret = 999999999; for (int a = 0; a <= 13; a++) { for (int b = 0; b <= 9; b++) { for (int c = 0; c <= 5; c++) { int value = a * 200 + b * 300 + c * 500; if (n == value) { ret = min(ret, (a / 5) * 1520 + (a % 5) * 380 + (b / 4) * 1870 * (b % 4) * 550 + (c / 3) * 2244 + (c % 3) * 850); } } } } printf("%d\n", ret); } return 0; }
#include <algorithm> #include <stdio.h> using namespace std; int n, ret; int main() { while (true) { scanf("%d", &n); if (n == 0) break; ret = 999999999; for (int a = 0; a <= 25; a++) { for (int b = 0; b <= 16; b++) { for (int c = 0; c <= 10; c++) { int value = a * 200 + b * 300 + c * 500; if (n == value) { ret = min(ret, (a / 5) * 1520 + (a % 5) * 380 + (b / 4) * 1870 + (b % 4) * 550 + (c / 3) * 2244 + (c % 3) * 850); } } } } printf("%d\n", ret); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 16, 31, 16, 31, 16, 17, 72]]
1
186
8
#include <bits/stdc++.h> #define mk make_pair using namespace std; int sum; set<pair<pair<int, int>, int>> s; void dfs(int a, int b, int c, int n) { if (s.count(mk(mk(a, b), c))) return; s.insert(mk(mk(a, b), c)); if (n == 0) { int aa = 0, bb = 0, cc = 0; if (a >= 5) aa = a / 5 * 1520; if (b >= 4) bb = b / 4 * 1870; if (c >= 3) cc = c / 3 * 2244; sum = min(sum, aa + bb + cc + a % 5 * 380 + b % 4 * 550 + c % 3 * 850); } else { if (n - 200 >= 0) dfs(a + 1, b, c, n - 200); if (n - 300 >= 0) dfs(a, b + 1, c, n - 300); if (n - 500 >= 0) dfs(a, b, c + 1, n - 500); } } int main() { int a; while (cin >> a) { s.clear(); sum = 1e9; dfs(0, 0, 0, a); cout << sum << endl; } }
#include <bits/stdc++.h> #define mk make_pair using namespace std; int sum; set<pair<pair<int, int>, int>> s; void dfs(int a, int b, int c, int n) { if (s.count(mk(mk(a, b), c))) return; s.insert(mk(mk(a, b), c)); if (n == 0) { int aa = 0, bb = 0, cc = 0; if (a >= 5) aa = a / 5 * 1520; if (b >= 4) bb = b / 4 * 1870; if (c >= 3) cc = c / 3 * 2244; sum = min(sum, aa + bb + cc + a % 5 * 380 + b % 4 * 550 + c % 3 * 850); } else { if (n - 200 >= 0) dfs(a + 1, b, c, n - 200); if (n - 300 >= 0) dfs(a, b + 1, c, n - 300); if (n - 500 >= 0) dfs(a, b, c + 1, n - 500); } } int main() { int a; while (cin >> a, a) { s.clear(); sum = 1e9; dfs(0, 0, 0, a); cout << sum << endl; } }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
293
2
// 0-1 knapsack #include <cstring> #include <iostream> using namespace std; const int INF = (1 << 21); int main() { int w[7] = {0, 2, 3, 5, 10, 12, 15}; int c[7] = {0, 380, 500, 850, 1520, 1870, 2244}; int dp[7][51] = {}; for (int i = 0; i < 7; i++) { for (int j = 1; j < 51; j++) { dp[i][j] = INF; } } for (int i = 1; i < 7; i++) { for (int j = 1; j <= 50; j++) { if (w[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(dp[i - 1][j], dp[i][j - w[i]] + c[i]); } } int kg; while (cin >> kg) { if (kg == 0) break; cout << dp[6][kg / 100] << endl; } return 0; }
// 0-1 knapsack #include <cstring> #include <iostream> using namespace std; const int INF = (1 << 21); int main() { int w[7] = {0, 2, 3, 5, 10, 12, 15}; int c[7] = {0, 380, 550, 850, 1520, 1870, 2244}; int dp[7][51] = {}; for (int i = 0; i < 7; i++) { for (int j = 1; j < 51; j++) { dp[i][j] = INF; } } for (int i = 1; i < 7; i++) { for (int j = 1; j <= 50; j++) { if (w[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(dp[i - 1][j], dp[i][j - w[i]] + c[i]); } } int kg; while (cin >> kg) { if (kg == 0) break; cout << dp[6][kg / 100] << endl; } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 51, 83, 0, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 13]]
1
258
2
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, f, n) for (int i = f; i < int(n); ++i) #define rep(i, n) reep(i, 0, n) typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef complex<double> Point; int main() { int answers[64]; int dp[64][8][4][4]; rep(i, 51) { answers[i] = 1 << 29; rep(j, 5) rep(k, 4) rep(l, 3) { int ans = i + j + k + l ? 1 << 29 : 0; if (2 <= i && j) ans = min(ans, dp[i - 2][j - 1][k][l] + 380); if (10 <= i && !j) ans = min(ans, dp[i - 9][0][k][l] + 1520); if (3 <= i && k) ans = min(ans, dp[i - 3][j][k - 1][l] + 550); if (12 <= i && !k) ans = min(ans, dp[i - 12][j][0][l] + 1870); if (5 <= i && l) ans = min(ans, dp[i - 5][j][k][l - 1] + 850); if (15 <= i && !l) ans = min(ans, dp[i - 15][j][k][0] + 2244); dp[i][j][k][l] = ans; answers[i] = min(answers[i], ans); } } int weight; while (scanf("%d", &weight), weight) { printf("%d\n", answers[weight / 100]); } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, f, n) for (int i = f; i < int(n); ++i) #define rep(i, n) reep(i, 0, n) typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef complex<double> Point; int main() { int answers[64]; int dp[64][8][4][4]; rep(i, 51) { answers[i] = 1 << 29; rep(j, 5) rep(k, 4) rep(l, 3) { int ans = i + j + k + l ? 1 << 29 : 0; if (2 <= i && j) ans = min(ans, dp[i - 2][j - 1][k][l] + 380); if (10 <= i && !j) ans = min(ans, dp[i - 10][0][k][l] + 1520); if (3 <= i && k) ans = min(ans, dp[i - 3][j][k - 1][l] + 550); if (12 <= i && !k) ans = min(ans, dp[i - 12][j][0][l] + 1870); if (5 <= i && l) ans = min(ans, dp[i - 5][j][k][l - 1] + 850); if (15 <= i && !l) ans = min(ans, dp[i - 15][j][k][0] + 2244); dp[i][j][k][l] = ans; answers[i] = min(answers[i], ans); } } int weight; while (scanf("%d", &weight), weight) { printf("%d\n", answers[weight / 100]); } return 0; }
[["-", 28, 69, 28, 69, 341, 342, 0, 16, 12, 13], ["+", 28, 69, 28, 69, 341, 342, 0, 16, 12, 13]]
1
448
2
#include <algorithm> #include <cctype> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> using namespace std; int n; int main() { while (cin >> n) { if (n == 0) return 0; int ans = 9999; for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) for (int k = 0; k < 26; k++) { int w = 200 * i + 300 * j + 500 * k, v = 380 * 0.8 * (i - (i % 5)) + 380 * (i % 5) + 550 * 0.85 * (j - (j % 4)) + 550 * (j % 4) + 850 * 0.88 * (k - (k % 3)) + 850 * (k % 3); if (w >= n) ans = min(ans, v); } cout << ans << endl; } }
#include <algorithm> #include <cctype> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> using namespace std; int n; int main() { while (cin >> n) { if (n == 0) return 0; int ans = 9999; for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) for (int k = 0; k < 26; k++) { int w = 200 * i + 300 * j + 500 * k, v = 380 * 0.8 * (i - (i % 5)) + 380 * (i % 5) + 550 * 0.85 * (j - (j % 4)) + 550 * (j % 4) + 850 * 0.88 * (k - (k % 3)) + 850 * (k % 3); if (w == n) ans = min(ans, v); } cout << ans << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
199
2
#include <algorithm> #include <climits> #include <iostream> using namespace std; int priceA(int amount) { if (amount % 200 != 0) { return -1; } amount /= 200; return (amount / 5 * 5) * 380 * 80 / 100 + (amount % 5) * 380; } int priceB(int amount) { if (amount % 300 != 0) { return -1; } amount /= 300; return (amount / 4 * 4) * 550 * 85 / 100 + (amount % 4) * 550; } int priceC(int amount) { if (amount % 500 != 0) { return -1; } amount /= 500; return (amount / 3 * 3) * 850 * 88 / 100 + (amount % 3) * 850; } int main() { while (true) { int amount; cin >> amount; if (amount == 0) { break; } int price = INT_MAX; for (int a = 0; a <= amount; a += 200) { for (int b = 0; b + a <= amount; b += 300) { for (int c = 0; c + b + a < amount; c += 500) { if (a + b + c != amount) { continue; } int pa = priceA(a), pb = priceB(b), pc = priceC(c); price = min(price, pa + pb + pc); } } } cout << price << endl; } return 0; }
#include <algorithm> #include <climits> #include <iostream> using namespace std; int priceA(int amount) { if (amount % 200 != 0) { return -1; } amount /= 200; return (amount / 5 * 5) * 380 * 80 / 100 + (amount % 5) * 380; } int priceB(int amount) { if (amount % 300 != 0) { return -1; } amount /= 300; return (amount / 4 * 4) * 550 * 85 / 100 + (amount % 4) * 550; } int priceC(int amount) { if (amount % 500 != 0) { return -1; } amount /= 500; return (amount / 3 * 3) * 850 * 88 / 100 + (amount % 3) * 850; } int main() { while (true) { int amount; cin >> amount; if (amount == 0) { break; } int price = INT_MAX; for (int a = 0; a <= amount; a += 200) { for (int b = 0; b + a <= amount; b += 300) { for (int c = 0; c + b + a <= amount; c += 500) { if (a + b + c != amount) { continue; } int pa = priceA(a), pb = priceB(b), pc = priceC(c); price = min(price, pa + pb + pc); } } } cout << price << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
303
2
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int f(int a, int b, int c) { int res = 0; res += a / 5 * 5 * 380 * 80 / 100 + a % 5 * 380; res += b / 4 * 4 * 550 * 85 / 100 + b % 4 * 550; res += c / 3 * 3 * 850 * 88 / 100 + c % 3 * 850; return res; } int main() { int n; while (n = in()) { int res = 1000000000; int a, b, c; for (a = 0; a <= n / 200 + 1; a++) { for (b = 0; b <= n / 300 + 1; b++) { for (c = 0; c <= n / 500 + 1; c++) { if (a * 200 + b * 300 + c * 500 >= n) { chmin(res, f(a, b, c)); // cout<<a<<" "<<b<<" "<<c<<" "<<f(a,b,c)<<endl; } } } } cout << res << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int, int> pint; #define mp make_pair template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; } template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } int f(int a, int b, int c) { int res = 0; res += a / 5 * 5 * 380 * 80 / 100 + a % 5 * 380; res += b / 4 * 4 * 550 * 85 / 100 + b % 4 * 550; res += c / 3 * 3 * 850 * 88 / 100 + c % 3 * 850; return res; } int main() { int n; while (n = in()) { int res = 1000000000; int a, b, c; for (a = 0; a <= n / 200 + 1; a++) { for (b = 0; b <= n / 300 + 1; b++) { for (c = 0; c <= n / 500 + 1; c++) { if (a * 200 + b * 300 + c * 500 == n) { chmin(res, f(a, b, c)); // cout<<a<<" "<<b<<" "<<c<<" "<<f(a,b,c)<<endl; } } } } cout << res << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
393
2
data=[] while True: n = int(input()) if n==0: break for i in range(n): spam=list(map(int,input().split())) spam.append(sum(spam)) data.append(spam) spam=[] for i in range(n+1): spam.append(sum(x[i] for x in data)) data.append(spam) for i in range(n+1): for j in range(n+1): print('{:5}'.format(data[i][j]),end='') print('')
while True: data=[] n = int(input()) if n==0: break for i in range(n): spam=list(map(int,input().split())) spam.append(sum(spam)) data.append(spam) spam=[] for i in range(n+1): spam.append(sum(x[i] for x in data)) data.append(spam) for i in range(n+1): for j in range(n+1): print('{:5}'.format(data[i][j]),end='') print('')
[["+", 36, 36, 36, 36, 0, 656, 0, 52, 0, 89], ["+", 36, 36, 36, 36, 0, 656, 0, 52, 15, 146], ["+", 36, 36, 36, 36, 0, 656, 0, 52, 0, 102], ["-", 36, 36, 36, 36, 0, 656, 0, 52, 0, 89], ["-", 36, 36, 36, 36, 0, 656, 0, 52, 15, 146], ["-", 36, 36, 36, 36, 0, 656, 0, 52, 0, 102]]
5
144
6
n = int(input()) while n != 0: input_list = [] for x in range(n): input_list.append(list(map(int, input().split(' ')))) for x in range(n): input_list[x].append(sum(input_list[x])) print(''.join(["{:>5}".format(n) for n in input_list])) input_len = len(input_list[0]) column_list = [] for x in range(input_len): tmp = 0 for y in range(n): tmp += input_list[y][x] column_list.append(tmp) print(''.join(["{:>5}".format(n) for n in column_list])) n = int(input())
n = int(input()) while n != 0: input_list = [] for x in range(n): input_list.append(list(map(int, input().split(' ')))) for x in range(n): input_list[x].append(sum(input_list[x])) print(''.join(["{:>5}".format(n) for n in input_list[x]])) input_len = len(input_list[0]) column_list = [] for x in range(input_len): tmp = 0 for y in range(n): tmp += input_list[y][x] column_list.append(tmp) print(''.join(["{:>5}".format(n) for n in column_list])) n = int(input())
[["+", 3, 4, 0, 658, 0, 659, 12, 206, 0, 70], ["+", 3, 4, 0, 658, 0, 659, 12, 206, 206, 22], ["+", 3, 4, 0, 652, 3, 4, 0, 658, 0, 73]]
5
172
3