提出詳細


ソースコード

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TeracoFiendNameWriter {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		File inFile = new File("B.txt");
		BufferedReader reader = null;
		FileReader fr = null;
		File outFile = new File("result.txt");
		BufferedWriter writer = null;
		FileWriter fw = null;
		try {
			// リーダ生成
			fr = new FileReader(inFile);
			reader = new BufferedReader(fr);
			// ライター生成
			fw = new FileWriter(outFile);
			writer = new BufferedWriter(fw);

			// テストケース数を読み込み
			int testCaseNum = Integer.parseInt(reader.readLine());

			// テストケース数の人の中からFriendがつく人物のみを書き出し
			for (int i = 1; i <= testCaseNum; i++) {
				String caseNumStr = "Case #" + i + ":";

				int num = Integer.parseInt(reader.readLine());
				List<String> friends = new ArrayList<String>();
				friends.clear();
				for (int j = 0; j < num; j++) {

					String[] who = reader.readLine().split(":");
					if ("Friend".equals(who[1])) {
						friends.add(who[0]);
					}
				}

				// 標準出力
				System.out.println(caseNumStr);

				// テキストファイルとして書き込み処理
				writer.write(caseNumStr);
				writer.newLine();
				if (friends.isEmpty()) {
					String noFriends = "Not Friends";
					System.out.println(noFriends);
					writer.write(noFriends);
					writer.newLine();
				} else {
					for (Iterator<String> it = friends.iterator(); it.hasNext();) {
						String friendsName = it.next();
						System.out.println(friendsName);
						writer.write(friendsName);
						writer.newLine();
					}
				}
			}
			// テキストファイルをフラッシュ
			writer.flush();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			// 各IOインスタンスのクローズ処理
			try {
				if (reader != null)
					reader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (reader != null)
					writer.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (fr != null)
					fr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				if (reader != null)
					fw.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}

提出情報

提出時間 2018-06-30 23:57:48
問題 B - きょうさんフレンズ
ユーザ名 soutarou1210
状態 正解
正解率 50/50
提出出力結果

テストケース情報

# 状態 詳細情報
テストケース 1 正解 詳細を見る
テストケース 2 正解 詳細を見る
テストケース 3 正解 詳細を見る
テストケース 4 正解 詳細を見る
テストケース 5 正解 詳細を見る
テストケース 6 正解 詳細を見る
テストケース 7 正解 詳細を見る
テストケース 8 正解 詳細を見る
テストケース 9 正解 詳細を見る
テストケース 10 正解 詳細を見る
テストケース 11 正解 詳細を見る
テストケース 12 正解 詳細を見る
テストケース 13 正解 詳細を見る
テストケース 14 正解 詳細を見る
テストケース 15 正解 詳細を見る
テストケース 16 正解 詳細を見る
テストケース 17 正解 詳細を見る
テストケース 18 正解 詳細を見る
テストケース 19 正解 詳細を見る
テストケース 20 正解 詳細を見る
テストケース 21 正解 詳細を見る
テストケース 22 正解 詳細を見る
テストケース 23 正解 詳細を見る
テストケース 24 正解 詳細を見る
テストケース 25 正解 詳細を見る
テストケース 26 正解 詳細を見る
テストケース 27 正解 詳細を見る
テストケース 28 正解 詳細を見る
テストケース 29 正解 詳細を見る
テストケース 30 正解 詳細を見る
テストケース 31 正解 詳細を見る
テストケース 32 正解 詳細を見る
テストケース 33 正解 詳細を見る
テストケース 34 正解 詳細を見る
テストケース 35 正解 詳細を見る
テストケース 36 正解 詳細を見る
テストケース 37 正解 詳細を見る
テストケース 38 正解 詳細を見る
テストケース 39 正解 詳細を見る
テストケース 40 正解 詳細を見る
テストケース 41 正解 詳細を見る
テストケース 42 正解 詳細を見る
テストケース 43 正解 詳細を見る
テストケース 44 正解 詳細を見る
テストケース 45 正解 詳細を見る
テストケース 46 正解 詳細を見る
テストケース 47 正解 詳細を見る
テストケース 48 正解 詳細を見る
テストケース 49 正解 詳細を見る
テストケース 50 正解 詳細を見る