結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2016-09-01 11:44:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 3,206 bytes |
コンパイル時間 | 4,132 ms |
コンパイル使用メモリ | 108,196 KB |
実行使用メモリ | 18,304 KB |
最終ジャッジ日時 | 2024-11-15 16:33:48 |
合計ジャッジ時間 | 3,821 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Collections.Generic;using System.IO;public class Test{public static void Solve(){int N = MyConsole.Int();int[,] Display = new int[N, N];// 一行目だけ先行処理for (int i = 0 ; i < N ; i++) Display[0, i] = (i + 1);int PERIOD = N * N;int Row = 0;int Col = N - 1;bool ptrSwitch = true;int moveCount = N - 1;for (int all = N + 1 ; all <= PERIOD ; ){int cnt = 0;if (ptrSwitch == true){// ↓for ( ; cnt < moveCount ; cnt++){Row++;Display[Row, Col] = all++;}// ←for (cnt = 0 ; cnt < moveCount ; cnt++){Col--;Display[Row, Col] = all++;}}else{// ↑for ( ; cnt < moveCount ; cnt++){Row--;Display[Row, Col] = all++;}// →for (cnt = 0 ; cnt < moveCount ; cnt++){Col++;Display[Row, Col] = all++;}}// 進む回数をデクリメントmoveCount--;// パターンフラグをひっくり返すptrSwitch = !ptrSwitch;}// 排出for (Row = 0 ; Row < N ; Row++){string line = null;for (Col = 0 ; Col < N ; Col++)line += Display[Row, Col].ToString("000 ");Console.WriteLine( line.Trim() );}}public static void Main(){MyConsole.Read(); Solve(); MyConsole.Finish();}}public static class MyConsole{private static List<string> ReadedLine = new List<string>();private static char[] buf = new char[1024];private static int i;public static void Read(){TextReader sr = Console.In;int Len = sr.Read( buf, 0, 1024 );var Line = string.Empty;for (int i = 0 ; i < Len ; i++){if (buf[i] >= 33 && buf[i] <= 126){Line += buf[i];}else if (Line.Length > 0){ReadedLine.Add( Line );Line = string.Empty;}}if (Line.Length > 0) ReadedLine.Add( Line );Console.SetOut( new StreamWriter( Console.OpenStandardOutput() ) { AutoFlush = false } );}public static string String() { return ReadedLine[i++]; }public static int Int() { return int.Parse( ReadedLine[i++] ); }public static long Long() { return long.Parse( ReadedLine[i++] ); }public static double Double() { return double.Parse( ReadedLine[i++] ); }public static void wLine( string output = null ){Console.WriteLine( output );}public static void Finish(){Console.Out.Flush();}}