C++ 363

[C/C++] 백준 30957번 빅데이터 vs 정보보호 vs 인공지능

코드 #include #include using namespace std; void answer(const string* _str) { string test = *_str; int countB = 0; // B의 개수 int countS = 0; // S의 개수 int countA = 0; // A의 개수 for (int i = 0; i < test.size(); i++) { if (test[i] == 'B') { // B의 개수 카운트 ++countB; } else if (test[i] == 'S') { // S의 개수 카운트 ++countS; } else { // A의 개수 카운트 ++countA; } } if (countB == countS && countS == countA) // 3개의 수가 같..

C++/백준 C++ 2023.12.19

[C/C++] 백준 12904번 A와 B

코드 #include #include #include // reverse using namespace std; // int* : 포인터, string& : 레퍼런스 int AB(const string _s, string& _t, int* _result) { while (true) { if (_s.size() == _t.size()) { if (_s == _t) { // 문자가 하나씩 남았을 때 같을 경우는 S를 T로 만들 수 있다. *_result = 1; } break; } if (_t[_t.size() - 1] == 'A') { // 문자열의 뒤에 A를 추가한다. -> 반대로 진행 맨 뒤 문자가 A일 경우 빼주기 _t.pop_back(); } else { // 문자열을 뒤집고 뒤에 B를 추가한다. -..

C++/백준 C++ 2023.12.17

[C/C++] 백준 1312번 소수

코드 #include using namespace std; // int* : 포인터, int& : 레퍼런스 int cal(int* _a, const int _b, const int _n, int& _result) { if (*_a % _b == 0){ // a가 b로 나눠어 떨어질 경우의 답은 0 return _result; } if (*_a > _b) { // 소숫점 아래 N번째 자리수를 구하기 위해 소수점이 아닌 부분은 미리 연산해 뺀다. *_a = *_a % _b; } for (int i = 0; i < _n; i++) { // n 만큼의 자리수까지 나누기 연산 진행 *_a = *_a * 10; _result = static_cast(*_a / _b); *_a = *_a % _b; } return ..

C++/백준 C++ 2023.12.16

[C/C++] 백준 11758번 CCW

코드 #include using namespace std; // 2차원 평면상에 3개의 점을 p1,p2,p3라고 가정하고, 각각의 좌표는xi,yi 라고 해보면, 외적의 결과를 다음과 같이 계산할 수 있다. // S=(x1y2+x2y3+x3y1)−(x2y1+x3y2+x1y3) int result(const int _x1,const int _y1, const int _x2, const int _y2, const int _x3, const int _y3, int* _sum) { *_sum=_x1 * _y2 + _x2 * _y3 + _x3 * _y1; *_sum=*_sum - _y1 * _x2 - _y2 * _x3 - _y3 * _x1; if (*_sum > 0) { // 반시계 방향 return 1; }els..

C++/백준 C++ 2023.12.15