반응형
그냥 쉬운 문제
#include < iostream > #include < string.h > // malloc #include < string > // cin >> str using namespace std; int answer; int sizeArr; int arr[49][49]; int main(void) { int tc; cin >> tc; for (int i = 1; i <= tc; i++) { // 입력 받기 cin >> sizeArr; for (int r = 0; r < sizeArr; r++) { string str; cin >> str; for (int c = 0; c < sizeArr; c++) { arr[r][c] = str[c]-48; } } // 연산 int half = sizeArr / 2; for (int r = 0; r < half; r++) { answer += arr[r][half]; answer += arr[sizeArr-1-r][half]; for (int k = 1; k <= r; k++) { answer += arr[r][half - k] + arr[r][half+k]; answer += arr[sizeArr-1-r][half - k] + arr[sizeArr - 1 - r][half + k]; } } answer += arr[half][half]; for (int k = 1; k <= half; k++) { answer += arr[half][half-k] + arr[half][half + k]; } cout << '#' << i << ' ' << answer << endl; answer = 0; // 초기화 } return 0; }
반응형