¸ð¹ü ´ä¾È¿¡´Â º¹±¸ÇÏ´Â ±â´ÉÀÌ ¾øÀ½
º¹±¸ÇÏ´Â ±â´ÉÀ» ±¸ÇöÇÏ¸é ´ÙÀ½°ú °°´Ù.
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 51 52 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> char processing[100]; void printRLE(char str[]) { char temp[10]; int n = strlen(str); for (int i = 0; i < n; i++) { int count = 1; while (i < n - 1 && str[i] == str[i + 1]) { count++; i++; } printf("%d%c", count, str[i]); sprintf(temp, "%d%c", count, str[i]); strcat(processing, temp); } printf("\n\n"); } void recover(char str[]) { int i, j, k, num; char collect[10]; int n = strlen(str); for (i = 0; i < n; i++) { j = 0; while(str[i+j] >= '0' && str[i+j] <= '9') { collect[j]=str[i+j++]; } collect[j] = 0; num = atoi(collect); for (k = 0; k < num; k++) { putchar(str[i + j]); } i += j; } } int main(void) { char s[100]; printf("¹®ÀÚ¿ ÀÔ·Â: "); gets_s(s, 100); printRLE(s); printf("º¹±¸ ¹®ÀÚ¿: "); recover(processing); return 0; } | cs |