๊ธฐ์ตํ ๊ฒ: string์ผ๋ก ํ์ ๋ฐ์ ์ด ์์๋ง๋ค ํ๋ ฌ๋ฐฐ์ด ์ ์ฅ
#include<iostream>
#include<string>
using namespace std;
int main() {
int T;
cin >> T;
int test_case;
for (int test_case = 1; test_case <= T; test_case++) {
string s;
int A[49][49] = { 0 , };
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> s;
for (int j = 0; j < N; j++) {
A[i][j] = s[j] - '0';
}
}
int sum = 0;
//์ ๋ง๋ฆ๋ชจ ์์ญ ๋ง์
for (int i = 0; i < N / 2; i++) {
for (int j = N / 2 - i; j <= N / 2 + i; j++) {
sum += A[i][j];
}
}
//์ค๊ฐ๋ถํฐ ๋ง๋ฆ๋ชจ ๋๊น์ง ๋ง์
for (int i = N / 2; i < N; i++) {
for (int j = i - N / 2; j <= N - (i - N / 2 + 1); j++) {
sum += A[i][j];
}
}
cout << "#" << test_case << " " << sum << "\n";
}
}
๋ฌธ์์ด.substr(์์์์น, ๊ธธ์ด)
#include <iostream>
using namespace std;
int main() {
string str1 = "abcde";
cout << str1.substr(0, 1) << endl; // a
cout << str1.substr(1, 1) << endl; // b
cout << str1.substr(2, 1) << endl; // c
cout << str1.substr(0, 2) << endl; // ab
cout << str1.substr(1, 2) << endl; // bc
}