#include #include #include #define STR_LENGTH 10 void str_cut(char*, int*); void paint(int, int, int); int main(void) { char str[STR_LENGTH]; int input[3] = {0}; int numCR1 = 0; int numCR2 = 0; int numCR = 0; int count = 0; int bCount = 0; int nextColumn= 0; int nextRow = 0; float decimal = 0.0; fgets(str, sizeof(str), stdin); str_cut(str, input); decimal = sqrt(input[0]); // printf("decimal1 = %f\n", decimal); numCR1 = (int)decimal; if(0 < (decimal - numCR1)) { numCR1 += 1; } // printf("numCR1 = %d\n", numCR1); decimal = input[0] / input[1]; // printf("decimal2 = %f\n", decimal); numCR2 = (int)decimal; if(0 < (decimal - numCR2)) { numCR2 += 1; } // printf("numCR2 = %d\n", numCR2); if(numCR1 >= numCR2) { numCR = numCR1; } else { numCR = numCR2; } printf("%d\n", numCR); nextRow = input[1]; for(int i=0; i < numCR; i++) { if(i >= nextRow) { nextColumn += input[1]; nextRow += input[1]; } for(int j=0; j < numCR; j++) { if(bCount == input[0]) { printf("."); continue; } if((count < input[1]) && (nextColumn <= j)) { printf("#"); count += 1; bCount += 1; } else { printf("."); } } printf("\n"); count = 0; } return 0; } /* 関数概要:渡された文字列を空白で分離し、数値に変換する 第1引数:文字列 第2引数:文字列から数値に変換して格納する配列 */ void str_cut(char* str, int* arg2) { int start_str = 0; int num = 0; //配列NO int i = 0; while('\0' != str[i]){ if(' ' == str[i]){ str[i] = '\0'; arg2[num] = atoi(&str[start_str]); ++num; ++i; start_str = i; } ++i; } arg2[num] = atoi(&str[start_str]); return; }