답안 #74357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74357 2018-08-31T11:02:26 Z khsoo01 이더리움과 비트코인 (FXCUP2_ethereum) C++11
1 / 1
2 ms 584 KB
#include "ethereum.h"
#include <stdio.h>
typedef long long ll;
const ll v1 = 100000000, v2 = 99999999;
 
bool haja (excinfo &I) {
	return (I.BTC == 0 || I.ETH == 0);
}
 
excinfo GetExchangePrice() {
	ll r1, r2;
	excinfo A = Exchange(v1), B = Exchange(v2);
	bool B1 = haja(A), B2 = haja(B);
	if(B1 && B2) {
		if(A.BTC) r1 = v1 / A.BTC;
		if(A.ETH) r2 = v1 / A.ETH;
		if(B.BTC) r1 = v2 / B.BTC;
		if(B.ETH) r2 = v2 / B.ETH;
	}
	else if(B1) {
		if(A.BTC) {
			r1 = v1 / A.BTC;
			r2 = (v2 - B.BTC * r1) / B.ETH;
		}
		if(A.ETH) {
			r2 = v1 / A.ETH;
			r1 = (v2 - B.ETH * r2) / B.BTC;
		}
	}
	else if(B2) {
		if(B.BTC) {
			r1 = v2 / B.BTC;
			r2 = (v1 - A.BTC * r1) / A.ETH;
		}
		if(B.ETH) {
			r2 = v2 / B.ETH;
			r1 = (v1 - A.ETH * r2) / A.BTC;
		}
	}
	else {
		r2 = (B.BTC*v1 - A.BTC*v2) / (B.BTC*A.ETH - A.BTC*B.ETH);
		r1 = (v1 - A.ETH*r2) / A.BTC;
	}
	return {r1, r2};
}

Compilation message

ethereum.cpp: In function 'excinfo GetExchangePrice()':
ethereum.cpp:44:16: warning: 'r2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  return {r1, r2};
                ^
ethereum.cpp:44:16: warning: 'r1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 520 KB Output is correct
9 Correct 2 ms 520 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 2 ms 576 KB Output is correct
16 Correct 2 ms 576 KB Output is correct
17 Correct 2 ms 576 KB Output is correct
18 Correct 2 ms 576 KB Output is correct
19 Correct 2 ms 576 KB Output is correct
20 Correct 2 ms 584 KB Output is correct