n = int(input())out = []for _ in range(n): # 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a name, k, a = input().split() filled = words = longest = 0 for _ in range(int(k)): line = input() # 줄 끝의 줄바꿈만 떼고 앞뒤 빈칸은 그대로 둔다 count = len(line.split()) # split()은 빈칸이 이어져도 낱말만 돌려준다 if count > 0: filled += 1 words += count longest = max(longest, len(line)) total = 0 for _ in range(int(a)): total += int(input().split()[1]) out.append(f"{name} {filled} {words} {longest} {total}")print("\n".join(out))
JavaScriptmain.js · 24 行
// 줄 단위로 읽어야 하니 빈칸으로 쪼개지 않는다. 통째로 trim()하지도 않는다: 끝의 빈 줄도 본문일 수 있다const lines = require("fs").readFileSync(0, "utf8").split("\n");let at = 0;const n = Number(lines[at++]);const out = [];for (let i = 0; i < n; i++) { // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a const [name, k, a] = lines[at++].split(" "); let filled = 0; let words = 0; let longest = 0; for (let j = 0; j < Number(k); j++) { const line = lines[at++]; // split(" ")은 빈칸이 이어지면 빈 문자열을 돌려주니 걸러 낸다 const count = line.split(" ").filter((w) => w !== "").length; if (count > 0) filled++; words += count; longest = Math.max(longest, line.length); } let total = 0; for (let j = 0; j < Number(a); j++) total += Number(lines[at++].split(" ")[1]); out.push(`${name} ${filled} ${words} ${longest} ${total}`);}console.log(out.join("\n"));
TypeScriptmain.ts · 26 行
import { readFileSync } from "node:fs";// 줄 단위로 읽어야 하니 빈칸으로 쪼개지 않는다. 통째로 trim()하지도 않는다: 끝의 빈 줄도 본문일 수 있다const lines: string[] = readFileSync(0, "utf8").split("\n");let at = 0;const n = Number(lines[at++]);const out: string[] = [];for (let i = 0; i < n; i++) { // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a const [name, k, a] = lines[at++].split(" "); let filled = 0; let words = 0; let longest = 0; for (let j = 0; j < Number(k); j++) { const line: string = lines[at++]; // split(" ")은 빈칸이 이어지면 빈 문자열을 돌려주니 걸러 낸다 const count = line.split(" ").filter((w) => w !== "").length; if (count > 0) filled++; words += count; longest = Math.max(longest, line.length); } let total = 0; for (let j = 0; j < Number(a); j++) total += Number(lines[at++].split(" ")[1]); out.push(`${name} ${filled} ${words} ${longest} ${total}`);}console.log(out.join("\n"));
JavaMain.java · 31 行
import java.io.*;import java.util.*;public class Main { public static void main(String[] args) throws IOException { // readLine은 줄바꿈만 떼고 한 줄을 통째로 돌려준다: 앞뒤 빈칸도 빈 줄도 그대로다 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a String[] head = br.readLine().split(" "); int k = Integer.parseInt(head[1]); int a = Integer.parseInt(head[2]); int filled = 0, words = 0, longest = 0; for (int j = 0; j < k; j++) { String line = br.readLine(); // StringTokenizer는 빈칸이 이어져도 낱말만 센다 int count = new StringTokenizer(line).countTokens(); if (count > 0) filled++; words += count; longest = Math.max(longest, line.length()); } int total = 0; for (int j = 0; j < a; j++) total += Integer.parseInt(br.readLine().split(" ")[1]); sb.append(head[0]).append(' ').append(filled).append(' ').append(words).append(' ') .append(longest).append(' ').append(total).append('\n'); } System.out.print(sb); }}
C#Main.cs · 32 行
using System;using System.Text;class Program{ static void Main() { // ReadLine은 줄바꿈만 떼고 한 줄을 통째로 돌려준다: 앞뒤 빈칸도 빈 줄도 그대로다 int n = int.Parse(Console.ReadLine()!); var sb = new StringBuilder(); for (int i = 0; i < n; i++) { // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a string[] head = Console.ReadLine()!.Split(' '); int k = int.Parse(head[1]), a = int.Parse(head[2]); int filled = 0, words = 0, longest = 0; for (int j = 0; j < k; j++) { string line = Console.ReadLine()!; // RemoveEmptyEntries가 없으면 빈칸이 이어질 때 빈 문자열이 낱말로 세어진다 int count = line.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length; if (count > 0) filled++; words += count; longest = Math.Max(longest, line.Length); } int total = 0; for (int j = 0; j < a; j++) total += int.Parse(Console.ReadLine()!.Split(' ')[1]); sb.Append($"{head[0]} {filled} {words} {longest} {total}\n"); } Console.Write(sb); }}
C++main.cpp · 45 行
#include <algorithm>#include <iostream>#include <sstream>#include <string>using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // 모든 줄을 getline으로 읽는다: cin >> 와 섞으면 >> 가 남긴 줄바꿈 때문에 getline이 빈 줄을 읽는다 string line; getline(cin, line); int n = stoi(line); for (int i = 0; i < n; i++) { // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a — 읽은 줄을 istringstream에 넣어 >> 로 꺼낸다 getline(cin, line); istringstream head(line); string name; int k, a; head >> name >> k >> a; int filled = 0, words = 0, longest = 0; for (int j = 0; j < k; j++) { getline(cin, line); // >> 는 빈칸이 이어져도 낱말만 하나씩 꺼낸다 istringstream body(line); string word; int count = 0; while (body >> word) count++; if (count > 0) filled++; words += count; longest = max(longest, (int)line.size()); } int total = 0; for (int j = 0; j < a; j++) { getline(cin, line); istringstream file(line); string fileName; int size; file >> fileName >> size; total += size; } cout << name << ' ' << filled << ' ' << words << ' ' << longest << ' ' << total << '\n'; } return 0;}
Cmain.c · 39 行
#include <stdio.h>#include <string.h>int main(void) { // 한 줄은 80자까지지만 줄바꿈과 끝 표시('\0')까지 들어갈 자리가 있어야 한다 char line[128]; int n; // 수도 fgets로 한 줄을 통째로 읽고 sscanf로 꺼낸다: scanf("%d")는 줄바꿈을 남겨 다음 fgets가 빈 줄을 읽는다 if (!fgets(line, sizeof line, stdin)) return 0; sscanf(line, "%d", &n); for (int i = 0; i < n; i++) { // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a char name[11]; int k = 0, a = 0; fgets(line, sizeof line, stdin); sscanf(line, "%10s %d %d", name, &k, &a); int filled = 0, words = 0, longest = 0; for (int j = 0; j < k; j++) { fgets(line, sizeof line, stdin); int len = (int)strcspn(line, "\n"); // 줄바꿈 앞까지의 길이: 앞뒤 빈칸은 그대로 센다 // 빈칸 다음에 빈칸이 아닌 글자가 나올 때마다 낱말 하나가 시작된다 int count = 0; for (int c = 0; c < len; c++) if (line[c] != ' ' && (c == 0 || line[c - 1] == ' ')) count++; if (count > 0) filled++; words += count; if (len > longest) longest = len; } int total = 0; for (int j = 0; j < a; j++) { int size = 0; fgets(line, sizeof line, stdin); sscanf(line, "%*s %d", &size); // %*s: 파일 이름은 읽고 버린다 total += size; } printf("%s %d %d %d %d\n", name, filled, words, longest, total); } return 0;}
Craykonmain.cray · 29 行
// 줄읽기는 줄바꿈만 떼고 한 줄을 통째로 돌려준다: 앞뒤 빈칸도 빈 줄도 그대로다n = 控制台.读行().转数字();循环 (i = 0; i < n; i++){ // 머리 줄: 이름, 본문 줄 수 k, 첨부 줄 수 a head = 控制台.读行().分割(); k = head[1].转数字(); a = head[2].转数字(); filled = 0; words = 0; longest = 0; 循环 (j = 0; j < k; j++) { line = 控制台.读行(); count = line.分割().数量; // 기준 없이 나누면 빈칸이 이어져도 낱말만 돌려준다 如果 (count > 0) { filled += 1; } words += count; longest = 数学.较大值(longest, line.长度); } total = 0; 循环 (j = 0; j < a; j++) { total += 控制台.读行().分割()[1].转数字(); } 控制台.输出(head[0] + " " + filled + " " + words + " " + longest + " " + total);}