https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV7GLXqKAWYDFAXB
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int T; cin >> T;
for (int t = 1; t <= T; t++) {
int N; cin >> N;
int sum = 0;
for (int k = 0; k < N; k++) {
string str; cin >> str;
int limit = (k <= N / 2) ? (1 + 2 * k) : (N - 2 * (k - N / 2));
int minus = (k <= N / 2) ? (N/2 - k) : (k - N / 2);
for (int i = 0; i < limit; i++) {
sum += (str[minus+i] - '0');
}
}
cout << "#" << t << " " << sum << endl;
}
return 0;
}
'전공공부 > 코딩테스트' 카테고리의 다른 글
(c++) SWEA "2806) N-Queen" (0) | 2022.05.28 |
---|---|
(c++) SWEA "1974) 스도쿠 검증" (0) | 2022.05.28 |
(c++) SWEA "2007) 패턴 마디의 길이" (0) | 2022.05.28 |
(c++) SWEA "1928) Base64 Decoder" (0) | 2022.05.28 |
(c++) SWEA "1204) 최빈수" (0) | 2022.05.25 |