문제
Mirko has found an old chessboard and a set of pieces in his attic. Unfortunately, the set contains only white pieces, and apparently an incorrect number of them. A set of pieces should contain:
One king
One queen
Two rooks
Two bishops
Two knights
Eight pawns
Mirko would like to know how many pieces of each type he should add or remove to make a valid set.
입력
The input consists of 6 integers on a single line, each between 0 and 10 (inclusive). The numbers are, in order, the numbers of kings, queens, rooks, bishops, knights and pawns in the set Mirko found.
출력
Output should consist of 6 integers on a single line; the number of pieces of each type Mirko should add or remove. If a number is positive, Mirko needs to add that many pieces. If a number is negative, Mirko needs to remove pieces.
체스판에 흰색 체스말이 6종류중에 일부 없거나 추가로 더 있음
입력되는 int 는 0 ~ 10 까지의 정수 ,remove하거나 add 해야할 숫자를
첫 줄에 출력하는 문제
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main()
{
//체스판에 흰색만 세팅되어있음
// 1킹 1퀸 2룩 2 비숍 2나이트 8폰
// 숫자가 이상하게 세팅되어있다고할때 주어진 숫자에서 remove add 해서 올바른 숫자로 맞추기
//킹 퀸 룩 비숍 나이트 폰 순으로 숫자가 입력된
// 출력은 6개의 인트 양수라면 기물의 갯수 + , 음수라면 기물의갯수 -
// ex ) 0 1 2 2 2 7 - > output 1 0 0 0 0 1
vector <int> chess = { 1,1,2,2,2,8 };
int input;// string 으로 받아야되나
for (int i = 0; i < 6; i++)
{
cin >> input;
cout << chess[i] - input << " ";
}
}
백준 문제가 익숙하지않아서 공백으로 구분되고 공백을 붙여서 출력해야하는 부분을 이해를못해서
시간을많이 소요함
string 으로 받아서 int 로 캐스팅 한후에 chess를 빼주는 방법도있었지만
공백문자를 처리하기위해서는 sstream을 사용해야할것같고 그렇게되면 코드가 복잡해질것같아서
최대한 단순하게 만들었다