답안 #20474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20474 2017-02-12T02:01:23 Z Lower Boundary(#62, pica4500) 채점 시스템 (OJUZ11_judge) C++
0 / 100
1000 ms 2012 KB
#include<vector>
#include<string>
#include<algorithm>
#include<stdio.h>
using namespace std;

struct BigInteger {
	string integer;
	BigInteger(string _integer) : integer(_integer) {};
};

BigInteger operator+(BigInteger a, BigInteger b) {
	vector<int> aList, bList, resultList;
	for (int i = a.integer.size() - 1; i >= 0; i--) aList.push_back(a.integer[i] - '0');
	for (int i = b.integer.size() - 1; i >= 0; i--) bList.push_back(b.integer[i] - '0');
	int maxDigit = max(a.integer.size(), b.integer.size()) + 1;
	for (int i = 0; i < maxDigit - a.integer.size(); i++) aList.push_back(0);
	for (int i = 0; i < maxDigit - b.integer.size(); i++) bList.push_back(0);
	for (int i = 0; i < maxDigit; i++) resultList.push_back(0);
	for (int i = 0; i < maxDigit - 1; i++) {
		resultList[i] += (aList[i] + bList[i]);
		resultList[i + 1] += resultList[i] / 10;
		resultList[i] %= 10;
	}
	while (resultList.back() == 0 && resultList.size() != 1) resultList.pop_back();
	string result = "";
	for (int i = resultList.size() - 1; i >= 0; i--) {
		result += (resultList[i] + '0');
	}
	return BigInteger(result);
}
bool operator<(BigInteger a, BigInteger b) {
	if (a.integer.size() < b.integer.size()) return true;
	else if (a.integer.size() > b.integer.size()) return false;
	else return a.integer < b.integer;
}
bool operator==(BigInteger a, BigInteger b) {
	return a.integer == b.integer;
}
int main() {
	//std::ios::sync_with_stdio(false);
	int tc;
	scanf("%d", &tc);

	while (tc--) {
		char a1[100000], b1[100000];
		scanf("%s%s", &a1, &b1);
		string a = a1;
		string b = b1;
		string c;
		int result = (b.size() - a.size() - 1);
		for (int i = 0; i < b.size(); i++) c += '0';
		for (int i = 1; i < 10; i++) {
			c[0] = i + '0';
			if (BigInteger(c) + BigInteger(a) < BigInteger(b) || BigInteger(c) + BigInteger(a) == BigInteger(b)) {
				result++;
				break;
			}
		}
		if (result < 0) puts("0");
		else printf("%d\n", result);
	}
}

Compilation message

judge.cpp: In function 'BigInteger operator+(BigInteger, BigInteger)':
judge.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < maxDigit - a.integer.size(); i++) aList.push_back(0);
                    ^
judge.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < maxDigit - b.integer.size(); i++) bList.push_back(0);
                    ^
judge.cpp: In function 'int main()':
judge.cpp:47:25: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[100000]' [-Wformat=]
   scanf("%s%s", &a1, &b1);
                         ^
judge.cpp:47:25: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[100000]' [-Wformat=]
judge.cpp:52:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < b.size(); i++) c += '0';
                     ^
judge.cpp:43:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &tc);
                  ^
judge.cpp:47:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s%s", &a1, &b1);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 2012 KB Execution timed out
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 2012 KB Execution timed out
2 Correct 363 ms 2012 KB Output is correct
3 Correct 359 ms 2008 KB Output is correct
4 Correct 363 ms 2008 KB Output is correct
5 Correct 359 ms 2008 KB Output is correct
6 Correct 353 ms 2008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 2012 KB Execution timed out
2 Correct 363 ms 2012 KB Output is correct
3 Correct 359 ms 2008 KB Output is correct
4 Correct 363 ms 2008 KB Output is correct
5 Correct 359 ms 2008 KB Output is correct
6 Correct 353 ms 2008 KB Output is correct
7 Correct 609 ms 2004 KB Output is correct
8 Correct 603 ms 2012 KB Output is correct
9 Correct 636 ms 2012 KB Output is correct
10 Correct 599 ms 2012 KB Output is correct
11 Correct 139 ms 2008 KB Output is correct