답안 #42351

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42351 2018-02-26T10:12:49 Z milmillin Igra (COCI17_igra) C++14
100 / 100
2 ms 604 KB
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

int xa,xb,xc;
int ya,yb,yc;

bool check() {
	if (xa<0||xb<0||xc<0) return false;
	if (xb+xc<ya) return false;
	if (xa+xc<yb) return false;
	if (xa+xb<yc) return false;
	return true;
}

int main () {
	int n;
	scanf("%d",&n);
	string x;
	cin >> x;
	string y;
	cin >> y;
	xa=xb=xc=ya=yb=yc=0;
	for (int i=0;i<n;i++) {
		if (x[i]=='a') xa++;
		else if (x[i]=='b') xb++;
		else if (x[i]=='c') xc++;
		if (y[i]=='a') ya++;
		else if (y[i]=='b') yb++;
		else if (y[i]=='c') yc++;
	}
	string ans;
	for (int i=0;i<n;i++) {
		if (y[i]=='a') {
			xb--;
			ya--;
			if (check()) ans.push_back('b');
			else {
				xb++;
				xc--;
				ans.push_back('c');
			}
		} else if (y[i]=='b') {
			xa--;
			yb--;
			if (check()) ans.push_back('a');
			else {
				xa++;
				xc--;
				ans.push_back('c');
			}
		} else {
			xa--;
			yc--;
			if (check()) ans.push_back('a');
			else {
				xa++;
				xb--;
				ans.push_back('b');
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

igra.cpp: In function 'int main()':
igra.cpp:20:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 2 ms 548 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct