PE

baio2033 Reply 7 years 32 weeks ago
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char c = 0; char str[1000] = { 0 }; char chk[1000] = { 0 }; int num = 0; int chr_num = 0; int cnt = 0; int len; c = getchar(); while (c != EOF) { if (c != '\t' && c != '\n') { str[num] = c; num++; chr_num++; } else if (c == '\t') { if (chr_num % 4 == 0) { for (int i = 0; i<4; i++) { str[num] = ' '; num++; } } else if (chr_num % 4 == 1) { for (int i = 0; i<3; i++) { str[num] = ' '; num++; } } else if (chr_num % 4 == 2) { for (int i = 0; i<2; i++) { str[num] = ' '; num++; } } else if (chr_num % 4 == 3) { str[num] = ' '; num++; } } else if (c == '\n' || c == EOF) { if (c != EOF) { str[num] = c; num++; } len = strlen(str); while (cnt<len) { if (cnt % 4 == 3 && str[cnt] == ' ') { str[cnt] = '\t'; if (str[cnt - 1] == ' ' && chk[cnt - 1] != 1) { chk[cnt - 1] = 1; } if (str[cnt - 2] == ' ' && chk[cnt - 1] == 1 && chk[cnt - 2] != 1) { chk[cnt - 2] = 1; } if (str[cnt - 3] == ' ' && chk[cnt - 2] == 1 && chk[cnt - 3] != 1) { chk[cnt - 3] = 1; } } cnt++; } for (int i = 0; i<len; i++) { if (chk[i] != 1) { printf("%c", str[i]); } } memset(chk, 0, 1000); memset(str, 0, 1000); num = 0; cnt = 0; } c = getchar(); } return 0; } 어디가 잘못된 것일까요
withcs1 Reply 7 years 31 weeks ago
줄바뀔때마다 chr_num을 초기화해주세요