[Coding] SWEA 2805, 1213 C++

๋ฌธ์ฑ„์˜ยท2023๋…„ 5์›” 18์ผ
0

๐Ÿ’ป2805

๊ธฐ์–ตํ•  ๊ฒƒ: 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";
	}



}

๐Ÿ’ป1213

๋ฌธ์ž์—ด.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

}

0๊ฐœ์˜ ๋Œ“๊ธ€