모든 문제는 C/C++, Java, Python 를 사용할수 있습니다.

기초다지기만 표준 입출력방식을 사용하고, 그외 모든 문제는 파일입출력으로 하셔야 채점이 가능합니다.

입력파일은 "input.txt", 출력파일은 "output.txt"입니다.

 

 

 

 

구현한 코드 :

 

#include <stdio.h> #include <stdlib.h> #include <string.h> #define OUT_FILE_NAME "output.txt" #define INPUT_FILE_NAME "input.txt" void ReadInput(int *row, int *col); void WriteOutput(char *text); void RemoveOutput(); void Proc(int row, int col); int main() { int row =0, col=0; RemoveOutput(); ReadInput(&row, &col); Proc(row, col); return 0; } void RemoveOutput() { unlink(OUT_FILE_NAME); } void Proc(int row, int col) { int direction=1; int i=0,j=0; int num = 1; char text[20] = {0}; for(i=0;i<row;i++) { for(j=0;j<col;j++) { if(direction) sprintf(text, "%d ", num++); else sprintf(text, "%d ", num--); WriteOutput(text); } if(direction) num--; else num++; direction = direction == 0? 1:0; WriteOutput("\n"); num += col; } } void WriteOutput(char *text) { FILE* fs; char *res=0; fs=fopen(OUT_FILE_NAME,"a"); if(fs) { while(*text != '\0') { fwrite(text, 1, 1, fs); text++; } fclose(fs); } } void ReadInput(int *row, int *col) { FILE* fs; char data[100]={0}; char *res=0; fs=fopen(INPUT_FILE_NAME,"r"); if(fs) { fread(data, sizeof(char),5,fs); *row = atoi(strtok(data, " ")); *col = atoi(strtok(0, " ")); fclose(fs); } } 

 

 

 

+ Recent posts