import sysdef main(): lines = sys.stdin.read().split("\n") # 빈 줄도 한 줄로 남는다 n = int(lines[0]) count = [] # count[d]: d+1일에 손익을 적은 참가자 수 total = [] best_value = [] best_who = [] for who in range(1, n + 1): # 인자 없는 split()은 빈 줄에서 빈 목록 []을 준다(split(" ")은 [""]를 준다) values = [int(t) for t in lines[who].split()] for d, v in enumerate(values): if d == len(count): # 이 날을 처음 적은 사람 count.append(0) total.append(0) best_value.append(v) best_who.append(who) count[d] += 1 total[d] += v if v > best_value[d]: # 같으면 앞 번호가 남는다 best_value[d] = v best_who[d] = who out = [str(len(count))] for d in range(len(count)): out.append(f"{count[d]} {total[d]} {best_who[d]}") print("\n".join(out))main()
JavaScriptmain.js · 29 行
// trim()을 하면 맨 뒤의 빈 줄(하나도 적지 않은 참가자)까지 사라지므로 하지 않는다const lines = require("fs").readFileSync(0, "utf8").split("\n");const n = Number(lines[0]);const count = [];const total = [];const bestValue = [];const bestWho = [];for (let who = 1; who <= n; who++) { const line = lines[who]; // "".split(" ")은 [""]이고 Number("")은 0이다. 빈 줄은 따로 빈 목록으로 둔다 const values = line === "" ? [] : line.split(" ").map(Number); values.forEach((v, d) => { if (d === count.length) { count.push(0); total.push(0); bestValue.push(v); bestWho.push(who); } count[d]++; total[d] += v; if (v > bestValue[d]) { bestValue[d] = v; bestWho[d] = who; } });}const out = [String(count.length)];for (let d = 0; d < count.length; d++) out.push(`${count[d]} ${total[d]} ${bestWho[d]}`);console.log(out.join("\n"));
TypeScriptmain.ts · 30 行
import { readFileSync } from "node:fs";// trim()을 하면 맨 뒤의 빈 줄(하나도 적지 않은 참가자)까지 사라지므로 하지 않는다const lines: string[] = readFileSync(0, "utf8").split("\n");const n = Number(lines[0]);const count: number[] = [];const total: number[] = [];const bestValue: number[] = [];const bestWho: number[] = [];for (let who = 1; who <= n; who++) { const line = lines[who]; // "".split(" ")은 [""]이고 Number("")은 0이다. 빈 줄은 따로 빈 목록으로 둔다 const values: number[] = line === "" ? [] : line.split(" ").map(Number); values.forEach((v, d) => { if (d === count.length) { count.push(0); total.push(0); bestValue.push(v); bestWho.push(who); } count[d]++; total[d] += v; if (v > bestValue[d]) { bestValue[d] = v; bestWho[d] = who; } });}const out: string[] = [String(count.length)];for (let d = 0; d < count.length; d++) out.push(`${count[d]} ${total[d]} ${bestWho[d]}`);console.log(out.join("\n"));
JavaMain.java · 37 行
import java.io.BufferedReader;import java.io.InputStreamReader;public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine().trim()); final int MAX_DAYS = 100; int[] count = new int[MAX_DAYS]; int[] total = new int[MAX_DAYS]; // 합은 많아야 10억이라 int로 된다 int[] bestValue = new int[MAX_DAYS]; int[] bestWho = new int[MAX_DAYS]; int days = 0; for (int who = 1; who <= n; who++) { String line = in.readLine(); // 빈 줄은 null이 아니라 "" // "".split(" ")은 [""]이라 parseInt("")에서 멈춘다. 빈 줄은 건너뛴다 if (line.isEmpty()) continue; String[] parts = line.split(" "); for (int d = 0; d < parts.length; d++) { int v = Integer.parseInt(parts[d]); if (count[d] == 0 || v > bestValue[d]) { // 첫 사람이거나 더 클 때만 바꾼다 bestValue[d] = v; bestWho[d] = who; } count[d]++; total[d] += v; } days = Math.max(days, parts.length); } StringBuilder out = new StringBuilder(); out.append(days).append('\n'); for (int d = 0; d < days; d++) { out.append(count[d]).append(' ').append(total[d]).append(' ').append(bestWho[d]).append('\n'); } System.out.print(out); }}
C#Main.cs · 41 行
using System;using System.Text;class Program{ static void Main() { int n = int.Parse(Console.ReadLine()!); const int MaxDays = 100; int[] count = new int[MaxDays]; int[] total = new int[MaxDays]; // 합은 많아야 10억이라 int로 된다 int[] bestValue = new int[MaxDays]; int[] bestWho = new int[MaxDays]; int days = 0; for (int who = 1; who <= n; who++) { string line = Console.ReadLine()!; // 빈 줄은 null이 아니라 "" // "".Split(' ')은 [""]이라 int.Parse("")에서 멈춘다. 빈 조각을 버리게 한다 string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); for (int d = 0; d < parts.Length; d++) { int v = int.Parse(parts[d]); if (count[d] == 0 || v > bestValue[d]) // 첫 사람이거나 더 클 때만 바꾼다 { bestValue[d] = v; bestWho[d] = who; } count[d]++; total[d] += v; } days = Math.Max(days, parts.Length); } var output = new StringBuilder(); output.Append(days).Append('\n'); for (int d = 0; d < days; d++) { output.Append(count[d]).Append(' ').Append(total[d]).Append(' ').Append(bestWho[d]).Append('\n'); } Console.Write(output); }}
C++main.cpp · 36 行
#include <iostream>#include <sstream>#include <string>#include <vector>int main() { std::ios::sync_with_stdio(false); std::string line; std::getline(std::cin, line); int n = std::stoi(line); std::vector<int> count, total, bestValue, bestWho; for (int who = 1; who <= n; who++) { // std::cin >> x는 줄 바꿈도 건너뛰어 빈 줄(참가자 하나)이 사라진다. 한 줄씩 읽는다 std::getline(std::cin, line); std::istringstream row(line); int v; for (std::size_t d = 0; row >> v; d++) { if (d == count.size()) { // 이 날을 처음 적은 사람 count.push_back(0); total.push_back(0); bestValue.push_back(v); bestWho.push_back(who); } count[d]++; total[d] += v; if (v > bestValue[d]) { // 같으면 앞 번호가 남는다 bestValue[d] = v; bestWho[d] = who; } } } std::cout << count.size() << '\n'; for (std::size_t d = 0; d < count.size(); d++) std::cout << count[d] << ' ' << total[d] << ' ' << bestWho[d] << '\n'; return 0;}
Cmain.c · 32 行
#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_DAYS 100int main(void) { char line[1100]; /* 한 줄은 1,000글자 이하 */ int count[MAX_DAYS] = {0}, total[MAX_DAYS] = {0}; int best_value[MAX_DAYS] = {0}, best_who[MAX_DAYS] = {0}; int n, days = 0; if (!fgets(line, sizeof line, stdin)) return 0; n = atoi(line); /* scanf("%d")는 줄 바꿈도 건너뛰어 빈 줄(참가자 하나)이 사라진다. 한 줄씩 읽는다 */ for (int who = 1; who <= n; who++) { if (!fgets(line, sizeof line, stdin)) break; int d = 0; for (char *tok = strtok(line, " \r\n"); tok; tok = strtok(NULL, " \r\n"), d++) { int v = (int)strtol(tok, NULL, 10); if (count[d] == 0 || v > best_value[d]) { /* 첫 사람이거나 더 클 때만 바꾼다 */ best_value[d] = v; best_who[d] = who; } count[d]++; total[d] += v; } if (d > days) days = d; } printf("%d\n", days); for (int d = 0; d < days; d++) printf("%d %d %d\n", count[d], total[d], best_who[d]); return 0;}
Craykonmain.cray · 34 行
n = 控制台.读行().转数字();count = [];total = [];bestValue = [];bestWho = [];循环 (who = 1; who <= n; who++){ 줄 = 控制台.读行(); // 빈 줄은 빈값이 아니라 "" // 인자 없는 나누기()는 빈 줄에서 빈 목록을 준다(나누기(" ")는 [""]를 준다) values = 줄.分割(); 循环 (d = 0; d < values.数量; d++) { v = values[d].转数字(); 如果 (d == count.数量) { count.添加(0); total.添加(0); bestValue.添加(v); bestWho.添加(who); } count[d] += 1; total[d] += v; 如果 (v > bestValue[d]) { bestValue[d] = v; bestWho[d] = who; } }}控制台.输出(count.数量);循环 (d = 0; d < count.数量; d++){ 控制台.输出(count[d] + " " + total[d] + " " + bestWho[d]);}