백준 2864 c++

magicdrill·2024년 2월 28일

백준 문제풀이

목록 보기
50/673

백준 2864 c++

입력된 문자열에 5 또는 6이 있을 경우, 5로 저장해 최소값, 6으로 저장해 최대값을 만들었다.
변수를 불필요하게 많이 선언한거 같다.

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void input_num(string *A, string *B)
{
	cin >> *A >> *B;

	return;
}

void find_answer(string A, string B)
{
	int i;
	int biggest_A, smallest_A, biggest_B, smallest_B;
	string biggest_A_str = "", smallest_A_str= "", biggest_B_str = "", smallest_B_str ="";

	for (i = 0; i < A.length(); i++)
	{
		if (A[i] == '5' || A[i] == '6')
		{
			biggest_A_str += '6';
			smallest_A_str += '5';
		}
		else
		{
			biggest_A_str += A[i];
			smallest_A_str += A[i];
		}
	}
	for (i = 0; i < B.length(); i++)
	{
		if (B[i] == '5' || B[i] == '6')
		{
			biggest_B_str += '6';
			smallest_B_str += '5';
		}
		else
		{
			biggest_B_str += B[i];
			smallest_B_str += B[i];
		}
	}
	biggest_A = stoi(biggest_A_str);
	smallest_A = stoi(smallest_A_str);
	biggest_B = stoi(biggest_B_str);
	smallest_B = stoi(smallest_B_str);
	cout << smallest_A + smallest_B << " " << biggest_A + biggest_B << "\n";

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//int A, B;
	string A, B;

	input_num(&A, &B);
	find_answer(A, B);

	return 0;
}

0개의 댓글