buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
|
|---|---|---|---|---|
#include <cstdlib>
#include <iostream>
#include <string>
#define DIGIT 80
using namespace std;
class largenum {
int nums[DIGIT];
bool overflow;
int most;
public:
largenum() {
overflow = false;
most = DIGIT - 1;
for (int i = 0; i < DIGIT; i++)
nums[i] = 0;
}
bool isoverflow() { return overflow; }
friend ostream &operator<<(ostream &out, largenum &l);
friend istream &operator>>(istream &is, largenum &l);
friend largenum operator+(largenum l1, largenum l2);
};
largenum operator+(largenum l1, largenum l2) {
bool carry = false;
largenum ans;
for (int i = DIGIT - 1; i >= 0; i--) {
int tmp = l1.nums[i] + l2.nums[i] + carry;
carry = bool((tmp) / 10);
ans.nums[i] = (tmp) % 10;
}
for (int i = 0; i < DIGIT; i++) {
if (ans.nums[i] != 0) {
ans.most = i;
break;
}
}
ans.overflow = carry;
return ans;
}
ostream &operator<<(ostream &out, largenum &l) {
for (int i = l.most; i < DIGIT; i++) {
out << l.nums[i];
}
return out;
}
istream &operator>>(istream &is, largenum &l) {
string str;
is >> str;
if (str.size() > DIGIT) {
l.overflow = true;
}
for (int i = 0; i < (int)str.size(); i++) {
int index = DIGIT - str.size() + i;
switch (str[i]) {
case '0':
l.nums[index] = 0;
break;
case '1':
l.nums[index] = 1;
break;
case '2':
l.nums[index] = 2;
break;
case '3':
l.nums[index] = 3;
break;
case '4':
l.nums[index] = 4;
break;
case '5':
l.nums[index] = 5;
break;
case '6':
l.nums[index] = 6;
break;
case '7':
l.nums[index] = 7;
break;
case '8':
l.nums[index] = 8;
break;
case '9':
l.nums[index] = 9;
break;
}
}
l.most = DIGIT - str.size();
return is;
}
int main() {
int num;
cin >> num;
while (num--) {
largenum a, b;
cin >> a >> b;
if (a.isoverflow() || b.isoverflow()) {
cout << "overflow" << endl;
continue;
}
a = a + b;
if (a.isoverflow()) {
cout << "overflow" << endl;
} else {
cout << a << endl;
}
}
return 0;
}
|
#include <cstdlib>
#include <iostream>
#include <string>
#define DIGIT 80
using namespace std;
class largenum {
int nums[DIGIT];
bool overflow;
int most;
public:
largenum() {
overflow = false;
most = DIGIT - 1;
for (int i = 0; i < DIGIT; i++)
nums[i] = 0;
}
bool isoverflow() { return overflow; }
friend ostream &operator<<(ostream &out, largenum &l);
friend istream &operator>>(istream &is, largenum &l);
friend largenum operator+(largenum l1, largenum l2);
};
largenum operator+(largenum l1, largenum l2) {
bool carry = false;
largenum ans;
for (int i = DIGIT - 1; i >= 0; i--) {
int tmp = l1.nums[i] + l2.nums[i] + carry;
carry = bool((tmp) / 10);
ans.nums[i] = (tmp) % 10;
}
for (int i = 0; i < DIGIT; i++) {
if (ans.nums[i] != 0) {
ans.most = i;
break;
}
}
ans.overflow = carry;
return ans;
}
ostream &operator<<(ostream &out, largenum &l) {
for (int i = l.most; i < DIGIT; i++) {
out << l.nums[i];
}
return out;
}
istream &operator>>(istream &is, largenum &l) {
string str;
is >> str;
if (str.size() > DIGIT) {
l.overflow = true;
} else {
for (int i = 0; i < (int)str.size(); i++) {
int index = DIGIT - str.size() + i;
switch (str[i]) {
case '0':
l.nums[index] = 0;
break;
case '1':
l.nums[index] = 1;
break;
case '2':
l.nums[index] = 2;
break;
case '3':
l.nums[index] = 3;
break;
case '4':
l.nums[index] = 4;
break;
case '5':
l.nums[index] = 5;
break;
case '6':
l.nums[index] = 6;
break;
case '7':
l.nums[index] = 7;
break;
case '8':
l.nums[index] = 8;
break;
case '9':
l.nums[index] = 9;
break;
}
}
l.most = DIGIT - str.size();
}
return is;
}
int main() {
int num;
cin >> num;
while (num--) {
largenum a, b;
cin >> a >> b;
if (a.isoverflow() || b.isoverflow()) {
cout << "overflow" << endl;
continue;
}
a = a + b;
if (a.isoverflow()) {
cout << "overflow" << endl;
} else {
cout << a << endl;
}
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 644
|
#include <algorithm>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
int n, i, j, flag;
char ch1[100], ch2[100];
cin >> n;
fgets(ch1, 100, stdin);
for (i = 0; i < n; i++) {
fgets(ch1, 100, stdin);
fgets(ch2, 100, stdin);
if (strlen(ch1) > 80 || strlen(ch2) > 80) {
cout << "overflow" << endl;
} else {
stack<int> st1, st2, sum;
sum.push(0);
for (j = 0; j < strlen(ch1); j++)
if (ch1[j] != '\n')
st1.push(ch1[j] - '0');
for (j = 0; j < strlen(ch2); j++)
if (ch2[j] != '\n')
st2.push(ch2[j] - '0');
while (!st1.empty() || !st2.empty()) {
if (st1.empty())
st1.push(0);
if (st2.empty())
st2.push(0);
flag = sum.top();
sum.pop();
sum.push((st1.top() + st2.top() + flag) % 10);
sum.push((st1.top() + st2.top() + flag) / 10);
st1.pop();
st2.pop();
}
if (sum.top() == 0)
sum.pop();
if (sum.size() > 80) {
cout << "overflow" << endl;
continue;
}
while (!sum.empty()) {
cout << sum.top();
sum.pop();
}
cout << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
int n, i, j, flag;
char ch1[100], ch2[100];
cin >> n;
fgets(ch1, 100, stdin);
for (i = 0; i < n; i++) {
fgets(ch1, 100, stdin);
fgets(ch2, 100, stdin);
if (strlen(ch1) > 81 || strlen(ch2) > 81) {
cout << "overflow" << endl;
} else {
stack<int> st1, st2, sum;
sum.push(0);
for (j = 0; j < strlen(ch1); j++)
if (ch1[j] != '\n')
st1.push(ch1[j] - '0');
for (j = 0; j < strlen(ch2); j++)
if (ch2[j] != '\n')
st2.push(ch2[j] - '0');
while (!st1.empty() || !st2.empty()) {
if (st1.empty())
st1.push(0);
if (st2.empty())
st2.push(0);
flag = sum.top();
sum.pop();
sum.push((st1.top() + st2.top() + flag) % 10);
sum.push((st1.top() + st2.top() + flag) / 10);
st1.pop();
st2.pop();
}
if (sum.top() == 0)
sum.pop();
if (sum.size() > 80) {
cout << "overflow" << endl;
continue;
}
while (!sum.empty()) {
cout << sum.top();
sum.pop();
}
cout << endl;
}
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
| 1
| 404
|
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
for (int y = 0; y < n; y++) {
string s, t;
cin >> s >> t;
int ls = s.size(), lt = t.size();
if (ls > 80 || lt > 80)
cout << "overflow" << endl;
else {
if (ls > lt) {
int r = ls - lt;
while (r > 0) {
t = "0" + t;
r = r - 1;
}
}
if (lt > ls) {
int r = -ls + lt;
while (r > 0) {
s = "0" + s;
r = r - 1;
}
}
int l = s.size();
int q = 0;
string ans = "";
for (int k = 0; k < l; k++) {
int w = t[l - k - 1] - '0' + s[l - k - 1] - '0';
w = w + q;
// cout<<w<<endl;
char z = '0' + w % 10;
ans = z + ans;
q = q / 10;
}
if (q == 1)
ans = '1' + ans;
if (q > 0 && l == 80)
cout << "overflow" << endl;
else
cout << ans << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
for (int y = 0; y < n; y++) {
string s, t;
cin >> s >> t;
int ls = s.size(), lt = t.size();
if (ls > 80 || lt > 80)
cout << "overflow" << endl;
else {
if (ls > lt) {
int r = ls - lt;
while (r > 0) {
t = "0" + t;
r = r - 1;
}
}
if (lt > ls) {
int r = -ls + lt;
while (r > 0) {
s = "0" + s;
r = r - 1;
}
}
int l = s.size();
int q = 0;
string ans = "";
for (int k = 0; k < l; k++) {
int w = t[l - k - 1] - '0' + s[l - k - 1] - '0';
w = w + q;
// cout<<w<<endl;
char z = '0' + w % 10;
ans = z + ans;
q = w / 10;
}
if (q == 1)
ans = '1' + ans;
if (q > 0 && l == 80)
cout << "overflow" << endl;
else
cout << ans << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
| 1
| 310
|
#include <algorithm>
#include <bits/stdc++.h>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
char c1[80], c2[80];
scanf("%s", &c1);
scanf("%s", &c2);
string s1, s2;
s1 = c1, s2 = c2;
if (s1 == "0" && s2 == "0") {
printf("0\n");
continue;
}
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
int n = max(s1.size(), s2.size()) + 1;
for (int i = s1.size(); i < n; i++) {
s1 += '0';
}
for (int i = s2.size(); i < n; i++) {
s2 += '0';
}
string res;
int b = 0;
for (int i = 0; i < max(s1.size(), s2.size()); i++) {
int u = s1[i] - '0' + s2[i] - '0' + b;
b = (u >= 10);
u %= 10;
res += u + '0';
}
reverse(res.begin(), res.end());
string res2;
int j = 0;
while (res[j] == '0')
j++;
for (; j < res.size(); j++) {
res2 += res[j];
}
if (res2.size() > 80) {
printf("overflow\n");
} else {
printf("%s\n", res2.c_str());
}
}
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
//???????????±?????§????????????
char c1[1000], c2[1000];
scanf("%s", &c1);
scanf("%s", &c2);
string s1, s2;
s1 = c1, s2 = c2;
if (s1 == "0" && s2 == "0") {
printf("0\n");
continue;
}
//?????¢?????????0????????§?????°???????????????
reverse(s1.begin(), s1.end());
reverse(s2.begin(), s2.end());
int n = max(s1.size(), s2.size()) + 1;
for (int i = s1.size(); i < n; i++) {
s1 += '0';
}
for (int i = s2.size(); i < n; i++) {
s2 += '0';
}
string res;
// b?????°?????????????????¨??????????????¨
int b = 0;
for (int i = 0; i < max(s1.size(), s2.size()); i++) {
int u = s1[i] - '0' + s2[i] - '0' + b;
b = (u >= 10);
u %= 10;
res += u + '0';
}
reverse(res.begin(), res.end());
string res2;
//????????¨?????´???0??????????????????0??\????????°??????????????¨?????????????????¨???????????????????¶????
int j = 0;
while (res[j] == '0')
j++;
for (; j < res.size(); j++) {
res2 += res[j];
}
if (res2.size() > 80) {
printf("overflow\n");
} else {
printf("%s\n", res2.c_str());
}
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 80, 81, 13]]
| 1
| 394
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, lengthof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
int n;
cin >> n;
while (n--) {
string s1, s2;
cin >> s1 >> s2;
string ans = "";
int s1l = s1.length();
int s2l = s2.length();
bool up = false;
REP(i, max(s1l, s2l)) {
int a = up ? 1 : 0;
if (s1l - i - 1 >= 0)
a += s1.c_str()[s1l - i - 1] - '0';
if (s2l - i - 1 >= 0)
a += s2.c_str()[s2l - i - 1] - '0';
up = (a >= 10);
ans = to_string(a % 10) + ans;
if (max(s1l, s2l) - i - 1 == 0 && up)
ans = "1" + ans;
}
if (ans.length() < 80)
cout << ans << endl;
else
cout << "overflow" << endl;
}
}
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, lengthof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
int n;
cin >> n;
while (n--) {
string s1, s2;
cin >> s1 >> s2;
string ans = "";
int s1l = s1.length();
int s2l = s2.length();
bool up = false;
REP(i, max(s1l, s2l)) {
int a = up ? 1 : 0;
if (s1l - i - 1 >= 0)
a += s1.c_str()[s1l - i - 1] - '0';
if (s2l - i - 1 >= 0)
a += s2.c_str()[s2l - i - 1] - '0';
up = (a >= 10);
ans = to_string(a % 10) + ans;
if (max(s1l, s2l) - i - 1 == 0 && up)
ans = "1" + ans;
}
if (ans.length() <= 80)
cout << ans << endl;
else
cout << "overflow" << endl;
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 415
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n, num1[101], num2[101], num3[102];
cin >> n;
for (int i = 0; i < n; ++i) {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
memset(num3, 0, sizeof(num3));
cin >> s;
for (int i = 0, len = s.size(); i < len; ++i) {
num1[i] = s[len - 1 - i] - '0';
}
cin >> s;
for (int i = 0, len = s.size(); i < len; ++i) {
num2[i] = s[len - 1 - i] - '0';
}
for (int i = 0, num; i < 101; ++i) {
num = num1[i] + num2[i] + num3[i];
num3[i] = num % 10;
num3[i + 1] = num / 10;
}
int ldigit = 0;
for (int i = 101; i >= 0; i--) {
if (num3[i] != 0) {
ldigit = i;
break;
}
}
if ((ldigit + 1) >= 80) {
cout << "overflow" << endl;
} else {
for (int i = ldigit; i >= 0; i--) {
cout << num3[i];
}
cout << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n, num1[101], num2[101], num3[102];
cin >> n;
for (int i = 0; i < n; ++i) {
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
memset(num3, 0, sizeof(num3));
cin >> s;
for (int i = 0, len = s.size(); i < len; ++i) {
num1[i] = s[len - 1 - i] - '0';
}
cin >> s;
for (int i = 0, len = s.size(); i < len; ++i) {
num2[i] = s[len - 1 - i] - '0';
}
for (int i = 0, num; i < 101; ++i) {
num = num1[i] + num2[i] + num3[i];
num3[i] = num % 10;
num3[i + 1] = num / 10;
}
int ldigit = 0;
for (int i = 101; i >= 0; i--) {
if (num3[i] != 0) {
ldigit = i;
break;
}
}
if ((ldigit + 1) > 80) {
cout << "overflow" << endl;
} else {
for (int i = ldigit; i >= 0; i--) {
cout << num3[i];
}
cout << endl;
}
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 324
|
#include <bits/stdc++.h>
using namespace std;
char str[102], str1[102], ans[102];
int sam(int ma1, int ma2) {
int co, carry = 0, a, b;
for (int i = 0; ma1 - i >= 0 || ma2 - i >= 0 || carry == 1; i++) {
if (ma1 - i >= 0 && ma2 - i >= 0) {
a = str[ma1 - i] - '0';
b = str1[ma2 - i] - '0';
if (a + b + carry >= 10) {
ans[i] = a + b + carry - 10 + '0';
carry = 1;
} else {
ans[i] = a + b + carry + '0';
carry = 0;
}
} else if (ma1 - i >= 0) {
a = str[ma1 - i] - '0';
if (a + carry >= 10) {
ans[i] = a + carry - 10 + '0';
carry = 1;
} else {
ans[i] = a + carry + '0';
carry = 0;
}
} else if (ma2 - i >= 0) {
b = str1[ma2 - i] - '0';
if (b + carry >= 10) {
ans[i] = b + carry - 10 + '0';
carry = 1;
} else {
ans[i] = b + carry + '0';
carry = 0;
}
} else {
ans[i] = '0' + 1;
return i;
}
co = i;
}
return co;
}
int main() {
int a, b, n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str >> str1;
a = strlen(str);
b = strlen(str1);
a = sam(a, b);
if (a > 80)
cout << "overflow\n";
else
for (int j = a; j > 0; j--)
cout << ans[j];
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
char str[102], str1[102], ans[102];
int sam(int ma1, int ma2) {
int co, carry = 0, a, b;
for (int i = 0; ma1 - i >= 0 || ma2 - i >= 0 || carry == 1; i++) {
if (ma1 - i >= 0 && ma2 - i >= 0) {
a = str[ma1 - i] - '0';
b = str1[ma2 - i] - '0';
if (a + b + carry >= 10) {
ans[i] = a + b + carry - 10 + '0';
carry = 1;
} else {
ans[i] = a + b + carry + '0';
carry = 0;
}
} else if (ma1 - i >= 0) {
a = str[ma1 - i] - '0';
if (a + carry >= 10) {
ans[i] = a + carry - 10 + '0';
carry = 1;
} else {
ans[i] = a + carry + '0';
carry = 0;
}
} else if (ma2 - i >= 0) {
b = str1[ma2 - i] - '0';
if (b + carry >= 10) {
ans[i] = b + carry - 10 + '0';
carry = 1;
} else {
ans[i] = b + carry + '0';
carry = 0;
}
} else {
ans[i] = '0' + 1;
return i;
}
co = i;
}
return co;
}
int main() {
int a, b, n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str >> str1;
a = strlen(str);
b = strlen(str1);
a = sam(a, b);
if (a > 80)
cout << "overflow" << endl;
else {
for (int j = a; j > 0; j--)
cout << ans[j];
cout << endl;
}
}
}
|
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 44], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 440
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a, b;
bool cu = false;
cin >> a >> b;
int al = a.length(), bl = b.length(), ans[101] = {0};
for (int i = 0; i < min(al, bl); i++) {
ans[i] = a[al - i - 1] + b[bl - i - 1] - 48 * 2;
if (cu)
ans[i]++;
if (ans[i] >= 10) {
ans[i] %= 10;
cu = true;
} else
cu = false;
}
for (int i = min(al, bl); i < max(al, bl); i++) {
if (al > bl)
ans[i] = a[al - i - 1] - 48 + cu;
else
ans[i] = b[bl - i - 1] - 48 + cu;
if (ans[i] >= 10) {
ans[i] %= 10;
cu = true;
} else
cu = false;
}
if (cu)
ans[max(al, bl)] = 1;
if (max(al, bl) + cu > 80)
cout << "overflow" << endl;
else
for (int i = (cu ? max(al, bl) : max(al, bl) - 1); i >= 0; i--)
cout << ans[i];
cout << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a, b;
bool cu = false;
cin >> a >> b;
int al = a.length(), bl = b.length(), ans[101] = {0};
for (int i = 0; i < min(al, bl); i++) {
ans[i] = a[al - i - 1] + b[bl - i - 1] - 48 * 2;
if (cu)
ans[i]++;
if (ans[i] >= 10) {
ans[i] %= 10;
cu = true;
} else
cu = false;
}
for (int i = min(al, bl); i < max(al, bl); i++) {
if (al > bl)
ans[i] = a[al - i - 1] - 48 + cu;
else
ans[i] = b[bl - i - 1] - 48 + cu;
if (ans[i] >= 10) {
ans[i] %= 10;
cu = true;
} else
cu = false;
}
if (cu)
ans[max(al, bl)] = 1;
if (max(al, bl) + cu > 80)
cout << "overflow";
else
for (int i = (cu ? max(al, bl) : max(al, bl) - 1); i >= 0; i--)
cout << ans[i];
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 335
|
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
string S, T;
int n, x[10000], a[10000], b[10000], cnt;
char U[11] = "0123456789";
int main() {
cin >> n;
for (int times = 0; times < n; times++) {
cin >> S >> T;
memset(x, 0, sizeof(x));
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < 10; j++) {
if (U[j] == S[i]) {
a[S.size() - 1 - i] = j;
}
}
}
for (int i = 0; i < T.size(); i++) {
for (int j = 0; j < 10; j++) {
if (U[j] == T[i]) {
b[T.size() - 1 - i] = j;
}
}
}
if (S.size() > 80 || T.size() > 80) {
cout << "OVERFLOW" << endl;
goto E;
}
for (int i = 0; i < 80; i++) {
x[i] += (a[i] + b[i]) % 10;
x[i + 1] += (a[i] + b[i]) / 10;
if (x[i] >= 10) {
x[i + 1] += x[i] / 10;
x[i] %= 10;
}
if (x[i + 1] >= 10) {
x[i + 2]++;
x[i + 1] %= 10;
}
}
cnt = 0;
if (x[80] > 0) {
cout << "OVERFLOW" << endl;
} else {
for (int i = 79; i >= 0; i--) {
if (x[i] > 0 || i == 0) {
cnt++;
}
if (cnt) {
cout << x[i];
}
}
cout << endl;
}
E:;
}
}
|
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
string S, T;
int n, x[10000], a[10000], b[10000], cnt;
char U[11] = "0123456789";
int main() {
cin >> n;
for (int times = 0; times < n; times++) {
cin >> S >> T;
memset(x, 0, sizeof(x));
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i < S.size(); i++) {
for (int j = 0; j < 10; j++) {
if (U[j] == S[i]) {
a[S.size() - 1 - i] = j;
}
}
}
for (int i = 0; i < T.size(); i++) {
for (int j = 0; j < 10; j++) {
if (U[j] == T[i]) {
b[T.size() - 1 - i] = j;
}
}
}
if (S.size() > 80 || T.size() > 80) {
cout << "overflow" << endl;
goto E;
}
for (int i = 0; i < 80; i++) {
x[i] += (a[i] + b[i]) % 10;
x[i + 1] += (a[i] + b[i]) / 10;
if (x[i] >= 10) {
x[i + 1] += x[i] / 10;
x[i] %= 10;
}
if (x[i + 1] >= 10) {
x[i + 2]++;
x[i + 1] %= 10;
}
}
cnt = 0;
if (x[80] > 0) {
cout << "overflow" << endl;
} else {
for (int i = 79; i >= 0; i--) {
if (x[i] > 0 || i == 0) {
cnt++;
}
if (cnt) {
cout << x[i];
}
}
cout << endl;
}
E:;
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 472
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
string a, b;
vector<int> ans;
int n, num, ai, bi, c = 0;
bool flag;
cin >> n;
if (n > 0 && n <= 100) {
for (int i = 0; i < n; i++) {
cin >> a >> b;
flag = false;
for (int j = 0; j < 100; j++) {
num = 0;
ai = a.size() - j - 1;
bi = b.size() - j - 1;
if (ai < 0 && bi < 0 && c == 0)
break;
if (ai >= 0)
num += a[ai] - 48;
if (bi >= 0)
num += b[bi] - 48;
ans.push_back((num + c) % 10);
if (num + c >= 10)
c = 1;
else
c = 0;
}
if (ans.size() > 80) {
flag = true;
}
if (flag) {
cout << "overflow";
} else {
for (int j = ans.size() - 1; j >= 0; --j) {
cout << ans[j];
}
cout << endl;
ans.clear();
}
}
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
string a, b;
vector<int> ans;
int n, num, ai, bi, c = 0;
bool flag;
cin >> n;
if (n > 0 && n <= 100) {
for (int i = 0; i < n; i++) {
cin >> a >> b;
flag = false;
for (int j = 0; j < 100; j++) {
num = 0;
ai = a.size() - j - 1;
bi = b.size() - j - 1;
if (ai < 0 && bi < 0 && c == 0)
break;
if (ai >= 0)
num += a[ai] - 48;
if (bi >= 0)
num += b[bi] - 48;
ans.push_back((num + c) % 10);
if (num + c >= 10)
c = 1;
else
c = 0;
}
if (ans.size() > 80) {
flag = true;
}
if (flag) {
cout << "overflow";
} else {
for (int j = ans.size() - 1; j >= 0; --j) {
cout << ans[j];
}
}
cout << endl;
ans.clear();
}
}
return 0;
}
|
[["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 279
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define LL long long
using namespace std;
static const LL INF = 1LL << 61LL;
typedef pair<int, int> PII;
string a, b;
string ans;
int M;
char t[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
void add(int n, int m, int c, string s) {
int k;
if (n - 1 < 0 && m - 1 < 0) {
if (c != 0)
s += t[c];
for (int i = s.size() - 1; i >= 0; --i) {
ans += s[i];
}
return;
}
if (n - 1 >= 0 && m - 1 >= 0)
k = a[n - 1] - '0' + b[m - 1] - '0' + c;
else if (n - 1 >= 0)
k = a[n - 1] - '0' + c;
else if (m - 1 >= 0)
k = b[m - 1] - '0' + c;
if (k >= 10) {
k -= 10;
c = 1;
}
add(n - 1, m - 1, c, s + t[k]);
}
/*bool MOD1(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%M;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}
bool MOD2(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%5;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}
bool MOD3(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%7;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}
bool MOD4(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%11;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}*/
int main() {
int n;
cin >> n;
rep(i, n) {
cin >> a >> b;
// cin>>M;
add(a.size(), b.size(), 0, "");
// if(!MOD1(ans)&&!MOD2(ans)&&!MOD3(ans)&&!MOD4(ans))cout<<ans<<endl;
// else cout<<"king is angry"<<endl;
if (ans.size() <= 80 && a.size() <= 80 && b.size() <= 80)
cout << ans << endl;
else
cout << "overflow" << endl;
ans.clear();
}
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define LL long long
using namespace std;
static const LL INF = 1LL << 61LL;
typedef pair<int, int> PII;
string a, b;
string ans;
int M;
char t[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
void add(int n, int m, int c, string s) {
int k;
// cout<<s<<" "<<a[n-1]<<" "<<b[m-1]<<" "<<c<<endl;
if (n - 1 < 0 && m - 1 < 0) {
if (c != 0)
s += t[c];
for (int i = s.size() - 1; i >= 0; --i) {
ans += s[i];
}
return;
}
if (n - 1 >= 0 && m - 1 >= 0)
k = a[n - 1] - '0' + b[m - 1] - '0' + c;
else if (n - 1 >= 0)
k = a[n - 1] - '0' + c;
else if (m - 1 >= 0)
k = b[m - 1] - '0' + c;
if (k >= 10) {
k -= 10;
c = 1;
} else
c = 0;
add(n - 1, m - 1, c, s + t[k]);
}
/*bool MOD1(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%M;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}
bool MOD2(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%5;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}
bool MOD3(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%7;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}
bool MOD4(string num){
bool res=false;
LL k=num.size();
LL mod;
int i=-1;
LL n=0;
while(k){
n=(n*10)+num[i+1]-'0';
mod=n%11;
n=mod;
k--;
i++;
}
if(mod==0)return true;
return false;
}*/
int main() {
int n;
cin >> n;
rep(i, n) {
cin >> a >> b;
// cin>>M;
add(a.size(), b.size(), 0, "");
// if(!MOD1(ans)&&!MOD2(ans)&&!MOD3(ans)&&!MOD4(ans))cout<<ans<<endl;
// else cout<<"king is angry"<<endl;
if (ans.size() <= 80 && a.size() <= 80 && b.size() <= 80)
cout << ans << endl;
else
cout << "overflow" << endl;
ans.clear();
}
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 75, 76, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 75, 76, 0, 1, 0, 35]]
| 1
| 405
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s1, s2;
cin >> s1;
cin >> s2;
int s1_itr = s1.length() - 1;
int s2_itr = s2.length() - 1;
bool is_shift = false;
int digit;
vector<int> sum;
while (s1_itr >= 0 || s2_itr >= 0) {
digit = 0;
if (s1_itr >= 0)
digit += s1[s1_itr] - '0';
if (s2_itr >= 0)
digit += s2[s2_itr] - '0';
if (is_shift)
digit += 1;
if (digit >= 10) {
is_shift = true;
digit = digit - 10;
} else {
is_shift = false;
}
sum.push_back(digit);
s1_itr--;
s2_itr--;
}
if (is_shift)
sum.push_back(1);
if (sum.size() >= 80) {
cout << "overflow" << endl;
} else {
for (int i = sum.size() - 1; i >= 0; i--) {
cout << sum[i];
}
cout << endl;
}
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s1, s2;
cin >> s1;
cin >> s2;
int s1_itr = s1.length() - 1;
int s2_itr = s2.length() - 1;
bool is_shift = false;
int digit;
vector<int> sum;
while (s1_itr >= 0 || s2_itr >= 0) {
digit = 0;
if (s1_itr >= 0)
digit += s1[s1_itr] - '0';
if (s2_itr >= 0)
digit += s2[s2_itr] - '0';
if (is_shift)
digit += 1;
if (digit >= 10) {
is_shift = true;
digit = digit - 10;
} else {
is_shift = false;
}
sum.push_back(digit);
s1_itr--;
s2_itr--;
}
if (is_shift)
sum.push_back(1);
if (sum.size() > 80) {
cout << "overflow" << endl;
} else {
for (int i = sum.size() - 1; i >= 0; i--) {
cout << sum[i];
}
cout << endl;
}
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 267
|
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
for (int N_i = 0; N_i < N; N_i++) {
bool overflow = false;
string str_data1, str_data2;
cin >> str_data1;
cin >> str_data2;
stack<int> data1, data2;
for (int data1_i = 0; data1_i < str_data1.size(); data1_i++) {
char buff[2];
buff[0] = str_data1[data1_i];
buff[1] = '\0';
data1.push(atoi(buff));
}
if (data1.size() >= 80) {
cout << "overflow" << endl;
continue;
}
for (int data2_i = 0; data2_i < str_data2.size(); data2_i++) {
char buff[2];
buff[0] = str_data2[data2_i];
buff[1] = '\0';
data2.push(atoi(buff));
}
if (data2.size() >= 80) {
cout << "overflow" << endl;
continue;
}
stack<int> sum;
int carry = 0;
int flag = data1.size() < data2.size() ? 0 : 1;
while (flag == 0 ? !data1.empty() : !data2.empty()) {
int presum = data1.top() + data2.top() + carry;
carry = presum / 10;
sum.push(presum % 10);
data1.pop();
data2.pop();
}
stack<int> *data;
data = data1.size() > data2.size() ? &data1 : &data2;
while (!data->empty()) {
int presum = data->top() + carry;
carry = presum / 10;
sum.push(presum % 10);
data->pop();
}
if (carry != 0)
sum.push(carry);
if (sum.size() >= 80) {
cout << "overflow" << endl;
continue;
}
if (overflow) {
cout << overflow << endl;
} else {
for (int sum_i = 0; !sum.empty(); sum_i++) {
cout << sum.top();
sum.pop();
}
cout << endl;
}
}
return 0;
}
|
#include <cstdlib>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
for (int N_i = 0; N_i < N; N_i++) {
bool overflow = false;
string str_data1, str_data2;
cin >> str_data1;
cin >> str_data2;
stack<int> data1, data2;
for (int data1_i = 0; data1_i < str_data1.size(); data1_i++) {
char buff[2];
buff[0] = str_data1[data1_i];
buff[1] = '\0';
data1.push(atoi(buff));
}
if (data1.size() > 80) {
cout << "overflow" << endl;
continue;
}
for (int data2_i = 0; data2_i < str_data2.size(); data2_i++) {
char buff[2];
buff[0] = str_data2[data2_i];
buff[1] = '\0';
data2.push(atoi(buff));
}
if (data2.size() > 80) {
cout << "overflow" << endl;
continue;
}
stack<int> sum;
int carry = 0;
int flag = data1.size() < data2.size() ? 0 : 1;
while (flag == 0 ? !data1.empty() : !data2.empty()) {
int presum = data1.top() + data2.top() + carry;
carry = presum / 10;
sum.push(presum % 10);
data1.pop();
data2.pop();
}
stack<int> *data;
data = data1.size() > data2.size() ? &data1 : &data2;
while (!data->empty()) {
int presum = data->top() + carry;
carry = presum / 10;
sum.push(presum % 10);
data->pop();
}
if (carry != 0)
sum.push(carry);
if (sum.size() > 80) {
cout << "overflow" << endl;
continue;
}
if (overflow) {
cout << overflow << endl;
} else {
for (int sum_i = 0; !sum.empty(); sum_i++) {
cout << sum.top();
sum.pop();
}
cout << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 477
|
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
int n;
string a, b;
cin >> n;
for (int j = 0; j < n; j++) {
cin >> a >> b;
int asize = a.length();
int bsize = b.length();
int smax = max(asize, bsize);
bool flag = false;
int s;
stringstream ss;
for (int i = 0; i < smax; i++) {
if (asize - i - 1 < 0)
s = strtol(b.substr(bsize - i - 1, 1).c_str(), NULL, 0);
else if (bsize - i - 1 < 0)
s = strtol(a.substr(asize - i - 1, 1).c_str(), NULL, 0);
else
s = strtol(a.substr(asize - i - 1, 1).c_str(), NULL, 0) +
strtol(b.substr(bsize - i - 1, 1).c_str(), NULL, 0);
if (flag)
s++;
ss << s % 10;
if (s > 9)
flag = true;
else
flag = false;
}
string ans = ss.str();
if (ans.length() > 80) {
cout << "overflow" << endl;
continue;
}
if (flag)
cout << 1;
for (string::reverse_iterator rit = ans.rbegin(); rit != ans.rend(); rit++)
cout << *rit;
cout << endl;
}
return 0;
}
|
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
int n;
string a, b;
cin >> n;
for (int j = 0; j < n; j++) {
cin >> a >> b;
int asize = a.length();
int bsize = b.length();
int smax = max(asize, bsize);
bool flag = false;
int s;
stringstream ss;
for (int i = 0; i < smax; i++) {
if (asize - i - 1 < 0)
s = strtol(b.substr(bsize - i - 1, 1).c_str(), NULL, 0);
else if (bsize - i - 1 < 0)
s = strtol(a.substr(asize - i - 1, 1).c_str(), NULL, 0);
else
s = strtol(a.substr(asize - i - 1, 1).c_str(), NULL, 0) +
strtol(b.substr(bsize - i - 1, 1).c_str(), NULL, 0);
if (flag)
s++;
ss << s % 10;
if (s > 9)
flag = true;
else
flag = false;
}
string ans = ss.str();
if (ans.length() + flag > 80) {
cout << "overflow" << endl;
continue;
}
if (flag)
cout << 1;
for (string::reverse_iterator rit = ans.rbegin(); rit != ans.rend(); rit++)
cout << *rit;
cout << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22]]
| 1
| 334
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
for (int j = 0; j < n; ++j) {
string numA;
string numB;
cin >> numA >> numB;
/*
if(numA.size()<numB.size())swap(numA,numB);
while(numA.size()>numB.size())numB="0"+numB;
*/
while (numA.size() != numB.size()) {
if (numA.size() < numB.size()) {
numA = "0" + numA;
} else {
numB = "0" + numB;
}
}
numA = "0" + numA;
numB = "0" + numB;
for (int i = numA.size() - 1; i >= 0; --i) {
int sum = 0;
sum = (numA[i] - '0') + (numB[i] - '0');
if (sum >= 10) {
sum -= 10;
numA[i - 1] += 1;
}
numA[i] = sum + '0';
}
if (numA.size() > 80) {
cout << "overflow" << endl;
continue;
}
if (numA.size() == 81 && numA[0] != '0') {
cout << "overflow" << endl;
continue;
}
for (int i = 0; i < numA.size(); ++i) {
if (i == 0 && numA[i] == '0')
continue;
cout << numA[i];
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
for (int j = 0; j < n; ++j) {
string numA;
string numB;
cin >> numA >> numB;
while (numA.size() != numB.size()) {
if (numA.size() < numB.size()) {
numA = "0" + numA;
} else {
numB = "0" + numB;
}
}
numA = "0" + numA;
numB = "0" + numB;
for (int i = numA.size() - 1; i >= 0; --i) {
int sum = 0;
sum = (numA[i] - '0') + (numB[i] - '0');
if (sum >= 10) {
sum -= 10;
numA[i - 1] += 1;
}
numA[i] = sum + '0';
}
if (numA.size() > 81) {
cout << "overflow" << endl;
continue;
}
if (numA.size() == 81 && numA[0] != '0') {
cout << "overflow" << endl;
continue;
}
for (int i = 0; i < numA.size(); ++i) {
if (i == 0 && numA[i] == '0')
continue;
cout << numA[i];
}
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 308
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
using namespace std;
int main(void) {
int n = 0;
string as;
string bs;
int a[100] = {};
int b[100] = {};
int c[100] = {};
int i = 0;
int alen = 0;
int blen = 0;
int clen = 0;
int k = 0;
int j = 0;
cin >> n;
for (j = 0; j < n; j++) {
for (i = 0; i < 100; i++)
a[i] = b[i] = c[i] = 0;
alen = 0;
blen = 0;
clen = 0;
k = 0;
cin >> as;
cin >> bs;
alen = as.size();
blen = bs.size();
for (i = 0; i < alen; i++) {
a[i] = as[alen - i - 1];
// printf("a[%d]=%d\n", i, a[i]);
switch (a[i]) {
case '0':
a[i] = 0;
break;
case '1':
a[i] = 1;
break;
case '2':
a[i] = 2;
break;
case '3':
a[i] = 3;
break;
case '4':
a[i] = 4;
break;
case '5':
a[i] = 5;
break;
case '6':
a[i] = 6;
break;
case '7':
a[i] = 7;
break;
case '8':
a[i] = 8;
break;
case '9':
a[i] = 9;
break;
}
}
for (i = 0; i < blen; i++) {
b[i] = bs[blen - i - 1];
// printf("b[%d]=%d\n", i, b[i]);
switch (b[i]) {
case '0':
b[i] = 0;
break;
case '1':
b[i] = 1;
break;
case '2':
b[i] = 2;
break;
case '3':
b[i] = 3;
break;
case '4':
b[i] = 4;
break;
case '5':
b[i] = 5;
break;
case '6':
b[i] = 6;
break;
case '7':
b[i] = 7;
break;
case '8':
b[i] = 8;
break;
case '9':
b[i] = 9;
break;
}
}
clen = (alen > blen) ? alen : blen;
for (i = 0; i < clen; i++) {
c[i] += a[i] + b[i];
c[i + 1] = c[i] / 10;
if (c[clen] != 0)
k = 1;
c[i] = c[i] % 10;
}
if (clen > 80 || c[80] != 0)
cout << "overflow" << endl;
for (i = clen + k - 1; i >= 0; i--)
cout << c[i];
puts("");
}
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
using namespace std;
int main(void) {
int n = 0;
string as;
string bs;
int a[100] = {};
int b[100] = {};
int c[100] = {};
int i = 0;
int alen = 0;
int blen = 0;
int clen = 0;
int k = 0;
int j = 0;
cin >> n;
for (j = 0; j < n; j++) {
for (i = 0; i < 100; i++)
a[i] = b[i] = c[i] = 0;
alen = 0;
blen = 0;
clen = 0;
k = 0;
cin >> as;
cin >> bs;
alen = as.size();
blen = bs.size();
for (i = 0; i < alen; i++) {
a[i] = as[alen - i - 1];
// printf("a[%d]=%d\n", i, a[i]);
switch (a[i]) {
case '0':
a[i] = 0;
break;
case '1':
a[i] = 1;
break;
case '2':
a[i] = 2;
break;
case '3':
a[i] = 3;
break;
case '4':
a[i] = 4;
break;
case '5':
a[i] = 5;
break;
case '6':
a[i] = 6;
break;
case '7':
a[i] = 7;
break;
case '8':
a[i] = 8;
break;
case '9':
a[i] = 9;
break;
}
}
for (i = 0; i < blen; i++) {
b[i] = bs[blen - i - 1];
// printf("b[%d]=%d\n", i, b[i]);
switch (b[i]) {
case '0':
b[i] = 0;
break;
case '1':
b[i] = 1;
break;
case '2':
b[i] = 2;
break;
case '3':
b[i] = 3;
break;
case '4':
b[i] = 4;
break;
case '5':
b[i] = 5;
break;
case '6':
b[i] = 6;
break;
case '7':
b[i] = 7;
break;
case '8':
b[i] = 8;
break;
case '9':
b[i] = 9;
break;
}
}
clen = (alen > blen) ? alen : blen;
for (i = 0; i < clen; i++) {
c[i] += a[i] + b[i];
c[i + 1] = c[i] / 10;
if (c[clen] != 0)
k = 1;
c[i] = c[i] % 10;
}
if (clen > 80 || c[80] != 0)
cout << "overflow" << endl;
else {
for (i = clen + k - 1; i >= 0; i--)
cout << c[i];
puts("");
}
}
}
|
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 670
|
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
char buf1[101], buf2[101];
bool overflowFLG;
int n, length1, length2, kuriagari, tmp, output[101];
scanf("%d", &n);
for (int loop = 0; loop < n; loop++) {
length1 = length2 = 0;
scanf("%s", buf1);
scanf("%s", buf2);
for (int i = 0; buf1[i] != '\0'; i++)
length1++;
for (int i = 0; buf2[i] != '\0'; i++)
length2++;
if (length1 >= 81 || length2 >= 81)
printf("overflow\n");
else {
overflowFLG = false;
kuriagari = 0;
if (length1 > length2) {
for (int k = 0; length1 - 1 - k >= 0; k++) {
tmp = kuriagari;
if (length2 - 1 - k >= 0) {
tmp = (buf1[length1 - 1 - k] - '0') + (buf2[length2 - 1 - k] - '0');
if (tmp >= 10) {
tmp %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
output[length1 - 1 - k] = tmp;
} else {
if (kuriagari == 0) {
output[length1 - 1 - k] = buf1[length1 - 1 - k] - '0';
} else {
output[length1 - 1 - k] = buf1[length1 - 1 - k] - '0' + kuriagari;
if (output[length1 - 1 - k] >= 10) {
output[length1 - 1 - k] %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
}
}
}
if (overflowFLG) {
printf("overflow\n");
} else {
if (kuriagari == 1)
printf("1");
for (int k = 0; k <= length1 - 1; k++) {
printf("%d", output[k]);
}
printf("\n");
}
} else {
for (int k = 0; length2 - 1 - k >= 0; k++) {
tmp = kuriagari;
if (length1 - 1 - k >= 0) {
tmp = (buf2[length2 - 1 - k] - '0') + (buf1[length1 - 1 - k] - '0');
if (tmp >= 10) {
tmp %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
output[length2 - 1 - k] = tmp;
} else {
if (kuriagari == 0) {
output[length2 - 1 - k] = buf2[length2 - 1 - k] - '0';
} else {
output[length2 - 1 - k] = buf2[length2 - 1 - k] - '0' + kuriagari;
if (output[length2 - 1 - k] >= 10) {
output[length2 - 1 - k] %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
}
}
}
if (overflowFLG) {
printf("overflow\n");
} else {
if (kuriagari == 1)
printf("1");
for (int k = 0; k <= length2 - 1; k++) {
printf("%d", output[k]);
}
printf("\n");
}
}
}
}
return 0;
}
|
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
char buf1[101], buf2[101];
bool overflowFLG;
int n, length1, length2, kuriagari, tmp, output[101];
scanf("%d", &n);
for (int loop = 0; loop < n; loop++) {
length1 = length2 = 0;
scanf("%s", buf1);
scanf("%s", buf2);
for (int i = 0; buf1[i] != '\0'; i++)
length1++;
for (int i = 0; buf2[i] != '\0'; i++)
length2++;
if (length1 >= 81 || length2 >= 81)
printf("overflow\n");
else {
overflowFLG = false;
kuriagari = 0;
if (length1 > length2) {
for (int k = 0; length1 - 1 - k >= 0; k++) {
tmp = kuriagari;
if (length2 - 1 - k >= 0) {
tmp +=
(buf1[length1 - 1 - k] - '0') + (buf2[length2 - 1 - k] - '0');
if (tmp >= 10) {
tmp %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
output[length1 - 1 - k] = tmp;
} else {
if (kuriagari == 0) {
output[length1 - 1 - k] = buf1[length1 - 1 - k] - '0';
} else {
output[length1 - 1 - k] = buf1[length1 - 1 - k] - '0' + kuriagari;
if (output[length1 - 1 - k] >= 10) {
output[length1 - 1 - k] %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
}
}
}
if (overflowFLG) {
printf("overflow\n");
} else {
if (kuriagari == 1)
printf("1");
for (int k = 0; k <= length1 - 1; k++) {
printf("%d", output[k]);
}
printf("\n");
}
} else {
for (int k = 0; length2 - 1 - k >= 0; k++) {
tmp = kuriagari;
if (length1 - 1 - k >= 0) {
tmp +=
(buf2[length2 - 1 - k] - '0') + (buf1[length1 - 1 - k] - '0');
if (tmp >= 10) {
tmp %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
output[length2 - 1 - k] = tmp;
} else {
if (kuriagari == 0) {
output[length2 - 1 - k] = buf2[length2 - 1 - k] - '0';
} else {
output[length2 - 1 - k] = buf2[length2 - 1 - k] - '0' + kuriagari;
if (output[length2 - 1 - k] >= 10) {
output[length2 - 1 - k] %= 10;
kuriagari = 1;
if (k == 79)
overflowFLG = true;
} else {
kuriagari = 0;
}
}
}
}
if (overflowFLG) {
printf("overflow\n");
} else {
if (kuriagari == 1)
printf("1");
for (int k = 0; k <= length2 - 1; k++) {
printf("%d", output[k]);
}
printf("\n");
}
}
}
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107]]
| 1
| 753
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> n1, n2;
int n, nn1, nn2, up, k, f, num[100];
char c;
cin >> n;
scanf("%c", &c);
for (int i = 0; i < n; i++) {
while (1) {
scanf("%c", &c);
if (c == '\n')
break;
n1.push(c - '0');
}
while (1) {
scanf("%c", &c);
if (c == '\n')
break;
n2.push(c - '0');
}
up = 0;
k = 0;
f = 0;
while (1) {
if (n1.size() != 0) {
nn1 = n1.top();
n1.pop();
} else
nn1 = 0;
if (n2.size() != 0) {
nn2 = n2.top();
n2.pop();
} else
nn2 = 0;
num[k] = (nn1 + nn2 + up) % 10;
up = (nn1 + nn2 + up) / 10;
if (n1.size() == 0 && n2.size() == 0 && up == 0) {
break;
}
k++;
if (k >= 80)
f = 1;
}
if (f == 1)
cout << "overflow" << endl;
else {
for (int i = k; i >= 0; i--)
cout << num[i];
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
int main() {
stack<int> n1, n2;
int n, nn1, nn2, up, k, f, num[1000];
char c;
cin >> n;
scanf("%c", &c);
for (int i = 0; i < n; i++) {
while (1) {
scanf("%c", &c);
if (c == '\n')
break;
n1.push(c - '0');
}
while (1) {
scanf("%c", &c);
if (c == '\n')
break;
n2.push(c - '0');
}
up = 0;
k = 0;
f = 0;
while (1) {
if (n1.size() != 0) {
nn1 = n1.top();
n1.pop();
} else
nn1 = 0;
if (n2.size() != 0) {
nn2 = n2.top();
n2.pop();
} else
nn2 = 0;
num[k] = (nn1 + nn2 + up) % 10;
up = (nn1 + nn2 + up) / 10;
if (n1.size() == 0 && n2.size() == 0 && up == 0) {
break;
}
k++;
if (k >= 80)
f = 1;
}
if (f == 1)
cout << "overflow";
else {
for (int i = k; i >= 0; i--)
cout << num[i];
}
cout << endl;
}
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 17, 151], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22]]
| 1
| 342
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n;
scanf("%d", &n);
rep(i, n) {
string s, t;
cin >> s >> t;
string ans;
int back = 0;
for (int j = 1; j <= min(s.size(), t.size()); j++) {
int d = s[s.size() - j] - '0' + t[t.size() - j] - '0' + back;
ans = (char)(d % 10 + '0') + ans;
back = d / 10;
}
string u;
if (s.size() > t.size())
u = s;
else
u = t;
for (int j = min(s.size(), t.size()) + 1; j <= u.size(); j++) {
int d = u[u.size() - j] - '0' + back;
ans = (char)(d % 10 + '0') + ans;
back = d / 10;
}
if (back)
ans = '1' + ans;
if (ans.size() > 80)
puts("overflow");
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n;
scanf("%d", &n);
rep(i, n) {
string s, t;
cin >> s >> t;
string ans;
int back = 0;
for (int j = 1; j <= min(s.size(), t.size()); j++) {
int d = s[s.size() - j] - '0' + t[t.size() - j] - '0' + back;
ans = (char)(d % 10 + '0') + ans;
back = d / 10;
}
string u;
if (s.size() > t.size())
u = s;
else
u = t;
for (int j = min(s.size(), t.size()) + 1; j <= u.size(); j++) {
int d = u[u.size() - j] - '0' + back;
ans = (char)(d % 10 + '0') + ans;
back = d / 10;
}
if (back)
ans = '1' + ans;
if (ans.size() > 80)
puts("overflow");
else
cout << ans << endl;
}
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 286
|
#include "bits/stdc++.h"
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
vector<int> v1(101), v2(101);
string str1, str2;
cin >> str1 >> str2;
for (int j = 0; j < str1.size(); j++)
v1[j] = str1[str1.size() - j - 1] - '0';
for (int j = 0; j < str2.size(); j++)
v1[j] = str2[str2.size() - j - 1] - '0';
for (int j = 0; j < 100; j++) {
v1[j] += v2[j];
if (v1[j] >= 10) {
v1[j] -= 10;
v1[j + 1]++;
}
}
int dig = 0;
for (int j = 100; j >= 0; j--) {
if (v1[j] != 0) {
dig = j;
break;
}
}
if (dig >= 80)
cout << "overflow" << endl;
else {
for (int j = dig; j >= 0; j--) {
cout << v1[j];
}
cout << endl;
}
}
}
|
#include "bits/stdc++.h"
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
vector<int> v1(101), v2(101);
string str1, str2;
cin >> str1 >> str2;
for (int j = 0; j < str1.size(); j++)
v1[j] = str1[str1.size() - j - 1] - '0';
for (int j = 0; j < str2.size(); j++)
v2[j] = str2[str2.size() - j - 1] - '0';
for (int j = 0; j < 100; j++) {
v1[j] += v2[j];
if (v1[j] >= 10) {
v1[j] -= 10;
v1[j + 1]++;
}
}
int dig = 0;
for (int j = 100; j >= 0; j--) {
if (v1[j] != 0) {
dig = j;
break;
}
}
if (dig >= 80)
cout << "overflow" << endl;
else {
for (int j = dig; j >= 0; j--) {
cout << v1[j];
}
cout << endl;
}
}
}
|
[["-", 0, 7, 8, 1, 0, 11, 31, 69, 28, 22], ["+", 0, 7, 8, 1, 0, 11, 31, 69, 28, 22]]
| 1
| 290
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string reverse(const string &str) {
string ret;
string::const_reverse_iterator it = str.rbegin();
for (; it != str.rend(); it++) {
ret.push_back(*it);
}
return ret;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string S1;
string S2;
int overflow = 0;
cin >> S1 >> S2;
if (S1.size() > 80 || S2.size() > 80) {
cout << "overflow" << endl;
} else {
S1 = reverse(S1);
S2 = reverse(S2);
S1.resize(80, '0');
S2.resize(80, '0');
int a = 0;
for (int i = 0; i < 80; i++) {
S1[i] += S2[i] - '0';
if (S1[i] > '9') {
if (i + 1 > 79) {
cout << "overflow";
overflow++;
}
S1[i + 1] += 1;
S1[i] -= 10;
}
if (S1[i] != '0')
a = i;
}
S1 = reverse(S1);
if (overflow == 0)
for (int i = 79 - a; i < 80; i++) {
cout << S1[i];
}
}
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string reverse(const string &str) {
string ret;
string::const_reverse_iterator it = str.rbegin();
for (; it != str.rend(); it++) {
ret.push_back(*it);
}
return ret;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string S1;
string S2;
int overflow = 0;
cin >> S1 >> S2;
if (S1.size() > 80 || S2.size() > 80) {
cout << "overflow";
} else {
S1 = reverse(S1);
S2 = reverse(S2);
S1.resize(80, '0');
S2.resize(80, '0');
int a = 0;
for (int i = 0; i < 80; i++) {
S1[i] += S2[i] - '0';
if (S1[i] > '9') {
if (i + 1 > 79) {
cout << "overflow";
overflow++;
}
S1[i + 1] += 1;
S1[i] -= 10;
}
if (S1[i] != '0')
a = i;
}
S1 = reverse(S1);
if (overflow == 0)
for (int i = 79 - a; i < 80; i++) {
cout << S1[i];
}
}
cout << endl;
}
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 57, 64, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 317
|
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES
#include <algorithm> // max??¢??°??????
#include <cmath> // ??°??????
#include <fstream> // ??????????????\??????
#include <iomanip> // stream???????????¢???
#include <iostream> // ?¨??????\??????
#include <string> // ???????????¢???
#include <vector> // ???????????????
using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
setprecision; // ?????°????°???°?????\???????????°????????????????????¨????????\???
using std::stoi;
using std::string;
using std::vector; // ????´???°????????????????????????
// ?¨??????¨?????¢??°
string calc(string str1, string str2) {
string res;
// ???????????????
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
// ?????°???????????????
while (str1.size() < str2.size()) {
str1 += '0';
}
while (str1.size() > str2.size()) {
str2 += '0';
}
int c = 0;
// 1????????¨????¨?????????????
for (size_t i = 0; i < str1.size(); i++) {
c = c + (str1[i] - '0') + (str2[i] - '0');
res += c % 10;
c = c / 10;
}
// ?????°?????????
if (c != 0)
res += c + '0';
if (res.size() > 80)
return "overflow";
reverse(res.begin(), res.end());
return res;
}
int main() {
int num;
string a;
string b;
vector<int> aa, bb;
cin >> num;
for (size_t i = 0; i < num; i++) {
cin >> a >> b;
cout << calc(a, b) << endl;
}
return 0;
}
|
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES
#include <algorithm> // max??¢??°??????
#include <cmath> // ??°??????
#include <fstream> // ??????????????\??????
#include <iomanip> // stream???????????¢???
#include <iostream> // ?¨??????\??????
#include <string> // ???????????¢???
#include <vector> // ???????????????
using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
setprecision; // ?????°????°???°?????\???????????°????????????????????¨????????\???
using std::stoi;
using std::string;
using std::vector; // ????´???°????????????????????????
// ?¨??????¨?????¢??°
string calc(string str1, string str2) {
string res;
// ???????????????
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
// ?????°???????????????
while (str1.size() < str2.size()) {
str1 += '0';
}
while (str2.size() < str1.size()) {
str2 += '0';
}
int c = 0;
// 1????????¨????¨?????????????
for (size_t i = 0; i < str1.size(); i++) {
c = c + (str1[i] - '0') + (str2[i] - '0');
res += c % 10 + '0';
c = c / 10;
}
// ?????°?????????
if (c != 0)
res += c + '0';
if (res.size() > 80)
return "overflow";
reverse(res.begin(), res.end());
return res;
}
int main() {
int num;
string a;
string b;
vector<int> aa, bb;
cin >> num;
for (size_t i = 0; i < num; i++) {
cin >> a >> b;
cout << calc(a, b) << endl;
}
return 0;
}
|
[["-", 15, 339, 51, 16, 31, 2, 63, 118, 28, 22], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 28, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 47], ["-", 15, 339, 51, 16, 12, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 18], ["+", 15, 339, 51, 16, 12, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 103, 0, 104], ["+", 0, 1, 0, 11, 12, 16, 12, 103, 0, 125]]
| 1
| 333
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INIT \
ios::sync_with_stdio(false); \
cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T> void MACRO_VAR_Scan(T &t) { cin >> t; }
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
cin >> first;
MACRO_VAR_Scan(rest...);
}
#define VEC(type, c, n) \
vector<type> c(n); \
for (auto &i : c) \
cin >> i;
#define MAT(type, c, m, n) \
vector<vector<type>> c(m, vector<type>(n)); \
for (auto &r : c) \
for (auto &i : r) \
cin >> i;
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout << endl;
#define OUT(d) cout << (d);
#define OUTL(d) \
cout << (d); \
BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a + n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define AREP(a, n) for (auto(a) : (n))
#define ALL(a) (a).begin(), (a).end()
#define IN(n, a, b) ((a) <= (n) && (n) < (b))
string sum(string a, string b) {
reverse(ALL(a));
reverse(ALL(b));
string ans = "";
if (a.size() > 80 || b.size() > 80)
return "overfrow";
int t = 0;
REP(k, max(a.size(), b.size())) {
int i = k < a.size() ? a[k] - '0' : 0;
int j = k < b.size() ? b[k] - '0' : 0;
int sum = i + j + t;
ans += (char)(sum % 10 + '0');
t = sum / 10;
}
if (t)
ans += (char)(t + '0');
if (ans.size() > 80)
return "overflow";
reverse(ALL(ans));
return ans;
}
signed main() {
INIT;
VAR(int, n);
REP(i, n) {
VAR(string, a, b);
OUTL(sum(a, b));
}
RET;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INIT \
ios::sync_with_stdio(false); \
cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T> void MACRO_VAR_Scan(T &t) { cin >> t; }
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
cin >> first;
MACRO_VAR_Scan(rest...);
}
#define VEC(type, c, n) \
vector<type> c(n); \
for (auto &i : c) \
cin >> i;
#define MAT(type, c, m, n) \
vector<vector<type>> c(m, vector<type>(n)); \
for (auto &r : c) \
for (auto &i : r) \
cin >> i;
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout << endl;
#define OUT(d) cout << (d);
#define OUTL(d) \
cout << (d); \
BR;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a + n, 0)
#define VSUM(v) accumulate(ALL(v), 0);
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define AREP(a, n) for (auto(a) : (n))
#define ALL(a) (a).begin(), (a).end()
#define IN(n, a, b) ((a) <= (n) && (n) < (b))
string sum(string a, string b) {
reverse(ALL(a));
reverse(ALL(b));
string ans = "";
if (a.size() > 80 || b.size() > 80)
return "overflow";
int t = 0;
REP(k, max(a.size(), b.size())) {
int i = k < a.size() ? a[k] - '0' : 0;
int j = k < b.size() ? b[k] - '0' : 0;
int sum = i + j + t;
ans += (char)(sum % 10 + '0');
t = sum / 10;
}
if (t)
ans += (char)(t + '0');
if (ans.size() > 80)
return "overflow";
reverse(ALL(ans));
return ans;
}
signed main() {
INIT;
VAR(int, n);
REP(i, n) {
VAR(string, a, b);
OUTL(sum(a, b));
}
RET;
}
|
[["-", 8, 9, 0, 57, 64, 37, 0, 5, 0, 6], ["+", 8, 9, 0, 57, 64, 37, 0, 5, 0, 6]]
| 1
| 480
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
#define DUMP(x) cout << #x << ":" << (x) << endl
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class T> istream &operator>>(istream &is, vector<T> &xs) {
for (auto &x : xs)
is >> x;
return is;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
struct BigInt {
public:
using LL = long long int;
static const LL BASE = 1000000000;
const int DIG = 9;
bool neg;
std::vector<LL> dig;
BigInt() : neg(false), dig(1, 0ll) {}
BigInt(const char *str) : BigInt(std::string(str)) {}
BigInt(const std::string &str) : neg(false) {
if (str.empty()) {
dig.assign(1, 0);
return;
}
int b = 0;
if (str[b] == '-') {
neg = true;
++b;
}
LL crt = 0;
LL p = 1;
for (int i = (int)(str.size()) - 1; i >= b; --i, p *= 10) {
if (p == BASE) {
dig.emplace_back(crt);
crt = 0;
p = 1;
}
if (!isdigit(str[i])) {
throw "Non digit is given.";
}
crt += p * (str[i] - '0');
}
if (crt)
dig.emplace_back(crt);
norm();
}
BigInt(LL x) : neg(x < 0), dig(1, std::abs(x)) {
for (unsigned int i = 0; i < dig.size(); ++i) {
if (dig[i] >= BASE) {
dig.emplace_back(dig[i] / BASE);
dig[i] %= BASE;
}
}
}
BigInt &operator=(const BigInt &rhs) {
neg = rhs.neg;
dig = rhs.dig;
return *this;
}
BigInt &operator=(LL x) { return *this = BigInt(x); }
BigInt &operator=(const char *s) { return *this = BigInt(s); }
BigInt &operator=(const std::string &s) { return *this = BigInt(s); }
bool iszero() const { return dig.size() == 1 && dig[0] == 0; }
BigInt operator-() const {
BigInt res = *this;
if (!res.iszero())
res.neg = !res.neg;
return res;
}
//! ignoring sign
static int comp(const BigInt &l, const BigInt &r) {
if (l.dig.size() != r.dig.size())
return (l.dig.size() < r.dig.size() ? -1 : 1);
for (int i = (int)(l.dig.size()) - 1; i >= 0; --i) {
if (l.dig[i] != r.dig[i])
return (l.dig[i] < r.dig[i] ? -1 : 1);
}
return 0;
}
//! add ignoring sign
static void add(BigInt &l, const BigInt &rhs) {
unsigned int i;
for (i = 0; i < rhs.dig.size(); ++i) {
if (l.dig.size() <= i) {
l.dig.emplace_back(rhs.dig[i]);
} else {
l.dig[i] += rhs.dig[i];
if (l.dig[i] >= BASE) {
l.dig[i] -= BASE;
if (l.dig.size() <= i + 1)
l.dig.emplace_back(0);
l.dig[i + 1]++;
} else if (l.dig[i] < 0) {
l.dig[i] += BASE;
if (l.dig.size() <= i + 1)
l.dig.emplace_back(0);
l.dig[i + 1]--;
}
}
}
for (; i < l.dig.size(); ++i)
if (l.dig[i] >= BASE) {
l.dig[i] -= BASE;
if (l.dig.size() <= i + 1)
l.dig.emplace_back(0);
l.dig[i + 1]++;
}
}
// subtract ignoring sign, supposed to l >= rhs
static void sub(BigInt &l, const BigInt &rhs) {
unsigned int i;
for (i = 0; i < rhs.dig.size(); ++i) {
l.dig[i] -= rhs.dig[i];
if (l.dig[i] < 0) {
l.dig[i] += BASE;
l.dig[i + 1]--;
}
}
for (; i < l.dig.size(); ++i)
if (l.dig[i] < 0) {
l.dig[i] += BASE;
l.dig[i + 1]--;
}
}
void flip() {
for (unsigned int i = 0; i < dig.size(); ++i)
dig[i] *= -1;
}
void norm() {
while (dig.size() > 1 && dig.back() == 0)
dig.pop_back();
if (iszero())
neg = false;
}
bool operator==(const BigInt &rhs) const {
if (neg != rhs.neg || dig.size() != rhs.dig.size())
return false;
return comp(*this, rhs) == 0;
}
bool operator<(const BigInt &rhs) const {
if (neg != rhs.neg)
return neg ? true : false;
if (neg)
return comp(rhs, *this) == -1;
return comp(*this, rhs) == -1;
}
bool operator<=(const BigInt &rhs) const {
if (neg != rhs.neg)
return neg ? true : false;
if (neg)
return comp(rhs, *this) <= 0;
return comp(*this, rhs) <= 0;
}
bool operator!=(const BigInt &rhs) const { return !(*this == rhs); }
bool operator>(const BigInt &rhs) const { return rhs < *this; }
bool operator>=(const BigInt &rhs) const { return rhs <= *this; }
// ignoring sign
void incl() {
for (unsigned int i = 0; i < dig.size(); ++i)
if (++dig[i] == BASE) {
dig[i] = 0;
if (i + 1 == dig.size()) {
dig.push_back(1);
break;
}
} else
break;
}
// ignoring sign
void decl() {
if (iszero()) {
dig[0] = 1;
neg = true;
return;
}
for (unsigned int i = 0; i < dig.size(); ++i)
if (--dig[i] == -1)
dig[i] = BASE - 1;
else
break;
norm();
}
BigInt &operator++() {
if (!neg)
incl();
else
decl();
return *this;
}
BigInt operator++(int) {
BigInt res = *this;
if (!neg)
incl();
else
decl();
return res;
}
BigInt &operator--() {
if (!neg)
decl();
else
incl();
return *this;
}
BigInt operator--(int) {
BigInt res = *this;
if (!neg)
decl();
else
incl();
return res;
}
BigInt &operator+=(const BigInt &rhs) {
if (!this->neg) {
if (!rhs.neg)
add(*this, rhs);
else {
if (comp(*this, rhs) >= 0)
sub(*this, rhs);
else {
flip();
add(*this, rhs);
neg = true;
}
}
} else {
if (!rhs.neg) {
if (comp(rhs, *this) >= 0) {
flip();
add(*this, rhs);
neg = false;
} else
sub(*this, rhs);
} else
add(*this, rhs);
}
norm();
return *this;
}
BigInt &operator-=(const BigInt &rhs) { return *this += -rhs; }
BigInt operator+(const BigInt &rhs) const {
BigInt res = *this;
return res += rhs;
}
BigInt operator-(const BigInt &rhs) const {
BigInt res = *this;
return res -= rhs;
}
BigInt operator*(const BigInt &rhs) const {
BigInt res;
res.dig.assign(dig.size() + rhs.dig.size() + 1, 0ll);
res.neg = neg ^ rhs.neg;
for (unsigned i = 0; i < rhs.dig.size(); ++i) {
if (rhs.dig[i] == 0)
continue;
for (unsigned j = 0; j < dig.size(); ++j) {
res.dig[i + j] += rhs.dig[i] * dig[j];
if (res.dig[i + j] >= BASE) {
res.dig[i + j + 1] += res.dig[i + j] / BASE;
res.dig[i + j] %= BASE;
}
}
}
res.norm();
return res;
}
BigInt operator*=(const BigInt &rhs) { return *this = *this * rhs; }
static void divll(BigInt &x, LL &r, LL d) {
bool lneg = x.neg;
x.neg ^= (d < 0);
if (d < 0)
d *= -1;
r = 0;
for (int i = (int)x.dig.size() - 1; i >= 0; --i) {
r = r * BASE + x.dig[i];
x.dig[i] = r / d;
r %= d;
}
x.norm();
if (r != 0 && lneg)
r *= -1;
}
void powB(LL x) {
if (iszero())
return;
while (x > 0) {
dig.insert(dig.begin(), 0ll);
--x;
}
}
static void divmod(BigInt &q, BigInt &r, const BigInt &lhs,
const BigInt &rhs) {
int cmp = comp(lhs, rhs);
if (cmp < 0) {
q.dig = std::vector<LL>(1, 0ll);
q.neg = false;
r = lhs;
return;
} else if (cmp == 0) {
q.dig = std::vector<LL>(1, 1ll);
q.neg = false;
r.dig = std::vector<LL>(1, 0ll);
r.neg = false;
return;
}
if (rhs.dig.size() == 1) {
LL rl;
q = lhs;
divll(q, rl, rhs.dig[0] * (rhs.neg ? -1ll : 1ll));
r = rl;
return;
}
q.neg = r.neg = false;
int u = lhs.dig.size() - rhs.dig.size() + 1;
q.dig.assign(u + 1, 0ll);
LL K = BASE / (rhs.dig.back() + 1);
BigInt ltmp = lhs, rtmp = rhs;
ltmp.neg = rtmp.neg = false;
if (K > 1) {
ltmp *= K;
rtmp *= K;
}
LL x = ltmp.dig.back() / rtmp.dig.back();
if (x == 0) {
--u;
x = (ltmp.dig.back() * BASE + ltmp.dig[ltmp.dig.size() - 2]) /
rtmp.dig.back();
}
BigInt w = 0ll;
while (true) {
w = rtmp;
w.powB(u);
if (comp(w, ltmp) > 0) {
--u;
continue;
}
while (true) {
w = rtmp * x;
w.powB(u);
if (comp(w, ltmp) <= 0)
break;
--x;
}
q.dig[u--] = x;
ltmp -= w;
if (ltmp == 0ll || u < 0)
break;
x = std::min(BASE - 1,
(ltmp.dig.back() * BASE + ltmp.dig[ltmp.dig.size() - 2]) /
rtmp.dig.back());
}
q.norm();
r = ltmp;
if (ltmp != 0ll)
divll(r, x, K);
q.neg = lhs.neg ^ rhs.neg;
r.neg = lhs.neg;
r.norm();
}
BigInt operator/(const BigInt &rhs) const {
BigInt q, r;
divmod(q, r, *this, rhs);
return q;
}
BigInt operator%(const BigInt &rhs) const {
BigInt q, r;
divmod(q, r, *this, rhs);
return r;
}
BigInt &operator/=(BigInt rhs) { return *this = *this / rhs; }
BigInt &operator%=(BigInt rhs) { return *this = *this % rhs; }
std::string to_string() const {
assert(!dig.empty());
std::string res = neg ? "-" : "";
std::ostringstream os;
os << std::to_string(dig.back());
for (int i = (int)(dig.size()) - 2; i >= 0; --i) {
os << std::setfill('0') << std::setw(DIG) << dig[i];
}
res += os.str();
return res;
}
// convert long long int anyway
LL to_ll() const {
LL res = 0, p = 1;
for (unsigned int i = 0; i < dig.size(); ++i) {
res += dig[i] * p;
p *= BASE;
}
return res * (neg ? -1ll : 1);
}
};
std::ostream &operator<<(std::ostream &os, const BigInt &x) {
return os << x.to_string();
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
while (--N) {
string s1, s2;
cin >> s1 >> s2;
BigInt x = s1, y = s2;
string ans = (x + y).to_string();
cout << (SZ(ans) > 80 ? "overflow" : ans) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
#define DUMP(x) cout << #x << ":" << (x) << endl
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class T> istream &operator>>(istream &is, vector<T> &xs) {
for (auto &x : xs)
is >> x;
return is;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
struct BigInt {
public:
using LL = long long int;
static const LL BASE = 1000000000;
const int DIG = 9;
bool neg;
std::vector<LL> dig;
BigInt() : neg(false), dig(1, 0ll) {}
BigInt(const char *str) : BigInt(std::string(str)) {}
BigInt(const std::string &str) : neg(false) {
if (str.empty()) {
dig.assign(1, 0);
return;
}
int b = 0;
if (str[b] == '-') {
neg = true;
++b;
}
LL crt = 0;
LL p = 1;
for (int i = (int)(str.size()) - 1; i >= b; --i, p *= 10) {
if (p == BASE) {
dig.emplace_back(crt);
crt = 0;
p = 1;
}
if (!isdigit(str[i])) {
throw "Non digit is given.";
}
crt += p * (str[i] - '0');
}
dig.emplace_back(crt);
norm();
}
BigInt(LL x) : neg(x < 0), dig(1, std::abs(x)) {
for (unsigned int i = 0; i < dig.size(); ++i) {
if (dig[i] >= BASE) {
dig.emplace_back(dig[i] / BASE);
dig[i] %= BASE;
}
}
}
BigInt &operator=(const BigInt &rhs) {
neg = rhs.neg;
dig = rhs.dig;
return *this;
}
BigInt &operator=(LL x) { return *this = BigInt(x); }
BigInt &operator=(const char *s) { return *this = BigInt(s); }
BigInt &operator=(const std::string &s) { return *this = BigInt(s); }
bool iszero() const { return dig.size() == 1 && dig[0] == 0; }
BigInt operator-() const {
BigInt res = *this;
if (!res.iszero())
res.neg = !res.neg;
return res;
}
//! ignoring sign
static int comp(const BigInt &l, const BigInt &r) {
if (l.dig.size() != r.dig.size())
return (l.dig.size() < r.dig.size() ? -1 : 1);
for (int i = (int)(l.dig.size()) - 1; i >= 0; --i) {
if (l.dig[i] != r.dig[i])
return (l.dig[i] < r.dig[i] ? -1 : 1);
}
return 0;
}
//! add ignoring sign
static void add(BigInt &l, const BigInt &rhs) {
unsigned int i;
for (i = 0; i < rhs.dig.size(); ++i) {
if (l.dig.size() <= i) {
l.dig.emplace_back(rhs.dig[i]);
} else {
l.dig[i] += rhs.dig[i];
if (l.dig[i] >= BASE) {
l.dig[i] -= BASE;
if (l.dig.size() <= i + 1)
l.dig.emplace_back(0);
l.dig[i + 1]++;
} else if (l.dig[i] < 0) {
l.dig[i] += BASE;
if (l.dig.size() <= i + 1)
l.dig.emplace_back(0);
l.dig[i + 1]--;
}
}
}
for (; i < l.dig.size(); ++i)
if (l.dig[i] >= BASE) {
l.dig[i] -= BASE;
if (l.dig.size() <= i + 1)
l.dig.emplace_back(0);
l.dig[i + 1]++;
}
}
// subtract ignoring sign, supposed to l >= rhs
static void sub(BigInt &l, const BigInt &rhs) {
unsigned int i;
for (i = 0; i < rhs.dig.size(); ++i) {
l.dig[i] -= rhs.dig[i];
if (l.dig[i] < 0) {
l.dig[i] += BASE;
l.dig[i + 1]--;
}
}
for (; i < l.dig.size(); ++i)
if (l.dig[i] < 0) {
l.dig[i] += BASE;
l.dig[i + 1]--;
}
}
void flip() {
for (unsigned int i = 0; i < dig.size(); ++i)
dig[i] *= -1;
}
void norm() {
while (dig.size() > 1 && dig.back() == 0)
dig.pop_back();
if (iszero())
neg = false;
}
bool operator==(const BigInt &rhs) const {
if (neg != rhs.neg || dig.size() != rhs.dig.size())
return false;
return comp(*this, rhs) == 0;
}
bool operator<(const BigInt &rhs) const {
if (neg != rhs.neg)
return neg ? true : false;
if (neg)
return comp(rhs, *this) == -1;
return comp(*this, rhs) == -1;
}
bool operator<=(const BigInt &rhs) const {
if (neg != rhs.neg)
return neg ? true : false;
if (neg)
return comp(rhs, *this) <= 0;
return comp(*this, rhs) <= 0;
}
bool operator!=(const BigInt &rhs) const { return !(*this == rhs); }
bool operator>(const BigInt &rhs) const { return rhs < *this; }
bool operator>=(const BigInt &rhs) const { return rhs <= *this; }
// ignoring sign
void incl() {
for (unsigned int i = 0; i < dig.size(); ++i)
if (++dig[i] == BASE) {
dig[i] = 0;
if (i + 1 == dig.size()) {
dig.push_back(1);
break;
}
} else
break;
}
// ignoring sign
void decl() {
if (iszero()) {
dig[0] = 1;
neg = true;
return;
}
for (unsigned int i = 0; i < dig.size(); ++i)
if (--dig[i] == -1)
dig[i] = BASE - 1;
else
break;
norm();
}
BigInt &operator++() {
if (!neg)
incl();
else
decl();
return *this;
}
BigInt operator++(int) {
BigInt res = *this;
if (!neg)
incl();
else
decl();
return res;
}
BigInt &operator--() {
if (!neg)
decl();
else
incl();
return *this;
}
BigInt operator--(int) {
BigInt res = *this;
if (!neg)
decl();
else
incl();
return res;
}
BigInt &operator+=(const BigInt &rhs) {
if (!this->neg) {
if (!rhs.neg)
add(*this, rhs);
else {
if (comp(*this, rhs) >= 0)
sub(*this, rhs);
else {
flip();
add(*this, rhs);
neg = true;
}
}
} else {
if (!rhs.neg) {
if (comp(rhs, *this) >= 0) {
flip();
add(*this, rhs);
neg = false;
} else
sub(*this, rhs);
} else
add(*this, rhs);
}
norm();
return *this;
}
BigInt &operator-=(const BigInt &rhs) { return *this += -rhs; }
BigInt operator+(const BigInt &rhs) const {
BigInt res = *this;
return res += rhs;
}
BigInt operator-(const BigInt &rhs) const {
BigInt res = *this;
return res -= rhs;
}
BigInt operator*(const BigInt &rhs) const {
BigInt res;
res.dig.assign(dig.size() + rhs.dig.size() + 1, 0ll);
res.neg = neg ^ rhs.neg;
for (unsigned i = 0; i < rhs.dig.size(); ++i) {
if (rhs.dig[i] == 0)
continue;
for (unsigned j = 0; j < dig.size(); ++j) {
res.dig[i + j] += rhs.dig[i] * dig[j];
if (res.dig[i + j] >= BASE) {
res.dig[i + j + 1] += res.dig[i + j] / BASE;
res.dig[i + j] %= BASE;
}
}
}
res.norm();
return res;
}
BigInt operator*=(const BigInt &rhs) { return *this = *this * rhs; }
static void divll(BigInt &x, LL &r, LL d) {
bool lneg = x.neg;
x.neg ^= (d < 0);
if (d < 0)
d *= -1;
r = 0;
for (int i = (int)x.dig.size() - 1; i >= 0; --i) {
r = r * BASE + x.dig[i];
x.dig[i] = r / d;
r %= d;
}
x.norm();
if (r != 0 && lneg)
r *= -1;
}
void powB(LL x) {
if (iszero())
return;
while (x > 0) {
dig.insert(dig.begin(), 0ll);
--x;
}
}
static void divmod(BigInt &q, BigInt &r, const BigInt &lhs,
const BigInt &rhs) {
int cmp = comp(lhs, rhs);
if (cmp < 0) {
q.dig = std::vector<LL>(1, 0ll);
q.neg = false;
r = lhs;
return;
} else if (cmp == 0) {
q.dig = std::vector<LL>(1, 1ll);
q.neg = false;
r.dig = std::vector<LL>(1, 0ll);
r.neg = false;
return;
}
if (rhs.dig.size() == 1) {
LL rl;
q = lhs;
divll(q, rl, rhs.dig[0] * (rhs.neg ? -1ll : 1ll));
r = rl;
return;
}
q.neg = r.neg = false;
int u = lhs.dig.size() - rhs.dig.size() + 1;
q.dig.assign(u + 1, 0ll);
LL K = BASE / (rhs.dig.back() + 1);
BigInt ltmp = lhs, rtmp = rhs;
ltmp.neg = rtmp.neg = false;
if (K > 1) {
ltmp *= K;
rtmp *= K;
}
LL x = ltmp.dig.back() / rtmp.dig.back();
if (x == 0) {
--u;
x = (ltmp.dig.back() * BASE + ltmp.dig[ltmp.dig.size() - 2]) /
rtmp.dig.back();
}
BigInt w = 0ll;
while (true) {
w = rtmp;
w.powB(u);
if (comp(w, ltmp) > 0) {
--u;
continue;
}
while (true) {
w = rtmp * x;
w.powB(u);
if (comp(w, ltmp) <= 0)
break;
--x;
}
q.dig[u--] = x;
ltmp -= w;
if (ltmp == 0ll || u < 0)
break;
x = std::min(BASE - 1,
(ltmp.dig.back() * BASE + ltmp.dig[ltmp.dig.size() - 2]) /
rtmp.dig.back());
}
q.norm();
r = ltmp;
if (ltmp != 0ll)
divll(r, x, K);
q.neg = lhs.neg ^ rhs.neg;
r.neg = lhs.neg;
r.norm();
}
BigInt operator/(const BigInt &rhs) const {
BigInt q, r;
divmod(q, r, *this, rhs);
return q;
}
BigInt operator%(const BigInt &rhs) const {
BigInt q, r;
divmod(q, r, *this, rhs);
return r;
}
BigInt &operator/=(BigInt rhs) { return *this = *this / rhs; }
BigInt &operator%=(BigInt rhs) { return *this = *this % rhs; }
std::string to_string() const {
assert(!dig.empty());
std::string res = neg ? "-" : "";
std::ostringstream os;
os << std::to_string(dig.back());
for (int i = (int)(dig.size()) - 2; i >= 0; --i) {
os << std::setfill('0') << std::setw(DIG) << dig[i];
}
res += os.str();
return res;
}
// convert long long int anyway
LL to_ll() const {
LL res = 0, p = 1;
for (unsigned int i = 0; i < dig.size(); ++i) {
res += dig[i] * p;
p *= BASE;
}
return res * (neg ? -1ll : 1);
}
};
std::ostream &operator<<(std::ostream &os, const BigInt &x) {
return os << x.to_string();
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
while (N--) {
string s1, s2;
cin >> s1 >> s2;
BigInt x = s1, y = s2;
string ans = (x + y).to_string();
cout << (SZ(ans) > 80 ? "overflow" : ans) << endl;
}
return 0;
}
|
[["-", 8, 123, 0, 14, 8, 9, 0, 57, 0, 121], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 51, 22], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["-", 8, 9, 0, 52, 15, 339, 51, 27, 17, 68], ["+", 8, 9, 0, 52, 15, 339, 51, 27, 17, 68]]
| 1
| 3,396
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a, b;
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
if (b.size() < a.size())
swap(a, b);
b += "0";
for (int i = 0; i < b.size() - 1; i++) {
int aa = i < a.size() ? a[i] - '0' : 0;
int bb = b[i] - '0';
int cc = aa + bb;
b[i] = (cc % 10) + '0';
// cout << aa << "+" << bb << "=" << cc << endl;
if (cc >= 10) {
b[i + 1]++;
}
}
if (b[b.size() - 1] == '0')
b = string(b.begin(), b.end() - 1);
reverse(b.begin(), b.end());
if (b.size() >= 80)
cout << "overflow" << endl;
else
cout << b << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a, b;
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
if (b.size() < a.size())
swap(a, b);
b += "0";
for (int i = 0; i < b.size() - 1; i++) {
int aa = i < a.size() ? a[i] - '0' : 0;
int bb = b[i] - '0';
int cc = aa + bb;
b[i] = (cc % 10) + '0';
// cout << aa << "+" << bb << "=" << cc << endl;
if (cc >= 10) {
b[i + 1]++;
}
}
if (b[b.size() - 1] == '0')
b = string(b.begin(), b.end() - 1);
reverse(b.begin(), b.end());
if (b.size() > 80)
cout << "overflow" << endl;
else
cout << b << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 274
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> sum(string A, string B);
int main() {
int n;
cin >> n;
string a, b;
for (int i = 0; i < n; i++) {
cin >> a;
cin >> b;
if ((int)a.size() > 80 || (int)b.size() > 80)
cout << "overflow\n";
else {
vector<int> tmp = sum(a, b);
if (tmp.size() > 80)
cout << "overflow\n";
else {
string S = "";
for (int i = 0; i < (int)tmp.size(); i++) {
S += to_string(tmp[i]);
}
cout << S << endl;
}
}
}
return 0;
}
vector<int> sum(string A, string B) {
int a_size = A.size() - 1;
int b_size = B.size() - 1;
int end = -1;
vector<int> tmp;
int Dr = 0;
while (true) {
if (a_size < 0) {
end = 0;
break;
}
if (b_size < 0) {
end = 1;
break;
}
int a = (int)A[a_size] - (int)'0';
int b = (int)B[b_size] - (int)'0';
int n = a + b + Dr;
if (n >= 10) {
tmp.push_back(n - 10);
Dr = 1;
} else {
Dr = 0;
tmp.push_back(n);
}
a_size--;
b_size--;
}
if (end == 0) {
for (int i = b_size; i >= 0; i--) {
int n = (int)B[b_size] - int('0') + Dr;
if (n >= 10) {
tmp.push_back(n - 10);
Dr = 1;
} else {
tmp.push_back(n);
Dr = 0;
}
}
} else if (end == 1) {
for (int i = a_size; i >= 0; i--) {
int n = (int)A[a_size] - int('0') + Dr;
if (n >= 10) {
tmp.push_back(n - 10);
Dr = 1;
} else {
tmp.push_back(n);
Dr = 0;
}
}
}
if (Dr == 1)
tmp.push_back(1);
reverse(tmp.begin(), tmp.end());
return tmp;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> sum(string A, string B);
int main() {
int n;
cin >> n;
string a, b;
for (int i = 0; i < n; i++) {
cin >> a;
cin >> b;
if ((int)a.size() > 80 || (int)b.size() > 80)
cout << "overflow\n";
else {
vector<int> tmp = sum(a, b);
if (tmp.size() > 80)
cout << "overflow\n";
else {
string S = "";
for (int i = 0; i < (int)tmp.size(); i++) {
S += to_string(tmp[i]);
}
cout << S << endl;
}
}
}
return 0;
}
vector<int> sum(string A, string B) {
int a_size = A.size() - 1;
int b_size = B.size() - 1;
int end = -1;
vector<int> tmp;
int Dr = 0;
while (true) {
if (a_size < 0) {
end = 0;
break;
}
if (b_size < 0) {
end = 1;
break;
}
int a = (int)A[a_size] - (int)'0';
int b = (int)B[b_size] - (int)'0';
int n = a + b + Dr;
if (n >= 10) {
tmp.push_back(n - 10);
Dr = 1;
} else {
Dr = 0;
tmp.push_back(n);
}
a_size--;
b_size--;
}
if (end == 0) {
for (int i = b_size; i >= 0; i--) {
int n = (int)B[i] - int('0') + Dr;
if (n >= 10) {
tmp.push_back(n - 10);
Dr = 1;
} else {
tmp.push_back(n);
Dr = 0;
}
}
} else if (end == 1) {
for (int i = a_size; i >= 0; i--) {
int n = (int)A[i] - int('0') + Dr;
if (n >= 10) {
tmp.push_back(n - 10);
Dr = 1;
} else {
tmp.push_back(n);
Dr = 0;
}
}
}
if (Dr == 1)
tmp.push_back(1);
reverse(tmp.begin(), tmp.end());
return tmp;
}
|
[["-", 31, 16, 31, 74, 51, 69, 341, 342, 0, 22], ["+", 31, 16, 31, 74, 51, 69, 341, 342, 0, 22]]
| 1
| 542
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
static const double EPS = 1e-9;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int main(void) {
int n;
cin >> n;
REP(i, n) {
string num1s;
string num2s;
cin >> num1s >> num2s;
if (num1s.size() > 80 || num2s.size() > 80)
cout << "overflow" << endl;
else {
int num1[81] = {0}, num2[81] = {0}, sum[81] = {0};
REP(i, num1s.size()) num1[num1s.size() - 1 - i] = (num1s[i] - '0');
REP(i, num2s.size()) num2[num2s.size() - 1 - i] = (num2s[i] - '0');
REP(i, 80) sum[i] = num1[i] + num2[i];
REP(i, 80) if (sum[i] > 9) {
sum[i + 1] += sum[i] / 10;
sum[i] = sum[i] % 10;
}
if (sum[80] > 9)
cout << "overflow" << endl;
else {
int first = 79;
while (sum[first] == 0 && first != 0)
first--;
for (int i = first; i >= 0; i--)
cout << sum[i];
cout << endl;
}
}
}
}
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
static const double EPS = 1e-9;
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int main(void) {
int n;
cin >> n;
REP(i, n) {
string num1s;
string num2s;
cin >> num1s >> num2s;
if (num1s.size() > 80 || num2s.size() > 80)
cout << "overflow" << endl;
else {
int num1[81] = {0}, num2[81] = {0}, sum[81] = {0};
REP(i, num1s.size()) num1[num1s.size() - 1 - i] = (num1s[i] - '0');
REP(i, num2s.size()) num2[num2s.size() - 1 - i] = (num2s[i] - '0');
REP(i, 80) sum[i] = num1[i] + num2[i];
REP(i, 80) if (sum[i] > 9) {
sum[i + 1] += sum[i] / 10;
sum[i] = sum[i] % 10;
}
if (sum[80] != 0)
cout << "overflow" << endl;
else {
int first = 79;
while (sum[first] == 0 && first != 0)
first--;
for (int i = first; i >= 0; i--)
cout << sum[i];
cout << endl;
}
}
}
}
|
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 338
|
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char ans[101];
char n1[101];
char n2[101];
int main() {
int d;
int h1, h2, limit;
for (cin >> d; d > 0; d--) {
for (int j = 0; j < 100; j++)
ans[j] = '0';
scanf("%s", n1);
scanf("%s", n2);
h1 = strlen(n1) - 1;
h2 = strlen(n2) - 1;
limit = max(h1, h2);
int i;
bool flg = false;
for (i = 0; i <= limit; i++, h1--, h2--) {
flg = false;
int n1_tmp = 0;
int n2_tmp = 0;
if (h1 >= 0) {
n1_tmp = n1[h1] - '0';
}
if (h2 >= 0) {
n2_tmp = n2[h2] - '0';
}
int sum = n1_tmp + n2_tmp;
if (sum >= 10) {
if (i == 79) {
i++;
flg = true;
break;
}
ans[i + 1] += 1;
sum = sum % 10;
flg = true;
}
if (ans[i] - '0' + sum > 9) {
if (i == 79) {
i++;
flg = true;
break;
}
ans[i] = ans[i] + (sum - 10);
ans[i + 1] += 1;
flg = true;
} else
ans[i] += sum;
}
if (flg) {
i++;
}
ans[i] = '\0';
if (i >= 80)
cout << "overflow" << endl;
else {
for (--i; i >= 0; i--) {
if (i >= 0)
cout << ans[i];
}
cout << endl;
}
// cout<<"size:"<<strlen(ans)<<endl;
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char ans[101];
char n1[101];
char n2[101];
int main() {
int d;
int h1, h2, limit;
for (cin >> d; d > 0; d--) {
for (int j = 0; j < 100; j++)
ans[j] = '0';
scanf("%s", n1);
scanf("%s", n2);
h1 = strlen(n1) - 1;
h2 = strlen(n2) - 1;
limit = max(h1, h2);
int i;
bool flg = false;
for (i = 0; i <= limit; i++, h1--, h2--) {
flg = false;
int n1_tmp = 0;
int n2_tmp = 0;
if (h1 >= 0) {
n1_tmp = n1[h1] - '0';
}
if (h2 >= 0) {
n2_tmp = n2[h2] - '0';
}
int sum = n1_tmp + n2_tmp;
if (sum >= 10) {
if (i == 79) {
i++;
flg = true;
break;
}
ans[i + 1] += 1;
sum = sum % 10;
flg = true;
}
if (ans[i] - '0' + sum > 9) {
if (i == 79) {
i++;
flg = true;
break;
}
ans[i] = ans[i] + (sum - 10);
ans[i + 1] += 1;
flg = true;
} else
ans[i] += sum;
}
if (flg) {
i++;
}
ans[i] = '\0';
if (i > 80)
cout << "overflow" << endl;
else {
for (--i; i >= 0; i--) {
if (i >= 0)
cout << ans[i];
}
cout << endl;
}
// cout<<"size:"<<strlen(ans)<<endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 400
|
// 0015 National Budget
// 80
ÜÅÌ2Â̮̫µZÊðo͹æ
// 1sÚÉf[^Zbgnª^¦çêé
//^¦çê½â»Ìaª80
𴦽êAoverflowÆo͵ľ³¢
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int n;
cin >> n;
while (n--) {
const int N = 3;
int i;
string a, b;
// 0ú»
char c[N + 2] = "";
cin >> a >> b;
//vZµâ·¢æ¤É½]
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int aSize, bSize;
aSize = a.size();
bSize = b.size();
//ܸÍAcÉ»ÌÜÜlðüêÄ¢
for (int i = 0; i < min(max(aSize, bSize), N + 1); i++) {
int s = 0;
if (i < aSize)
s += a[i] - '0';
if (i < bSize)
s += b[i] - '0';
c[i] += s;
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
//ã©ç©Ä¢ÁÄA0ÈO̶ª»ê½ç¶»·é
bool isAnswer = false;
for (i = sizeof(c) - 1; i >= 0; i--) {
if (c[i])
isAnswer = true;
if (isAnswer)
c[i] += '0';
}
//½]µÄ®¬
reverse(c, c + strlen(c));
//àµà80¶ÚªNULL¶Å êÎI[o[t[
if (c[N])
cout << "overflow" << endl;
//dlãA¦ª0ÈçNULL¶ÅÜéÌÅËÁÞ
else if (c[0] == '\0')
cout << '0' << endl;
else
cout << c << endl;
}
return 0;
}
|
// 0015 National Budget
// 80
ÜÅÌ2Â̮̫µZÊðo͹æ
// 1sÚÉf[^Zbgnª^¦çêé
//^¦çê½â»Ìaª80
𴦽êAoverflowÆo͵ľ³¢
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int n;
cin >> n;
while (n--) {
const int N = 80;
int i;
string a, b;
// 0ú»@æí©çÈ¢ÌÅKÉå«
char c[N + 10] = "";
cin >> a >> b;
//vZµâ·¢æ¤É½]
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int aSize, bSize;
aSize = a.size();
bSize = b.size();
//ܸÍAcÉ»ÌÜÜlðüêÄ¢
for (int i = 0; i < min(max(aSize, bSize), N + 1); i++) {
int s = 0;
if (i < aSize)
s += a[i] - '0';
if (i < bSize)
s += b[i] - '0';
c[i] += s;
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
//ã©ç©Ä¢ÁÄA0ÈO̶ª»ê½ç¶»·é
bool isAnswer = false;
for (i = sizeof(c) - 1; i >= 0; i--) {
if (c[i])
isAnswer = true;
if (isAnswer)
c[i] += '0';
}
//½]µÄ®¬
reverse(c, c + strlen(c));
//àµà80¶ÚªNULL¶Å êÎI[o[t[
if (c[N])
cout << "overflow" << endl;
//dlãA¦ª0ÈçNULL¶ÅÜéÌÅËÁÞ
else if (c[0] == '\0')
cout << '0' << endl;
else
cout << c << endl;
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 43, 49, 50, 49, 80, 81, 16, 12, 13], ["+", 0, 43, 49, 50, 49, 80, 81, 16, 12, 13]]
| 1
| 327
|
stack = []
while True:
try:
n = int(input)
except:
break
stack.append(n) if n else print(stack.pop())
|
stack = []
while True:
try:
n = int(input())
except:
break
stack.append(n) if n else print(stack.pop())
|
[["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
| 5
| 35
|
list = {}
while True:
try:
num = int(input())
if num == 0:
print(list.pop())
else:
list.append(num)
except:
break
|
list = []
while True:
try:
num = int(input())
if num == 0:
print(list.pop())
else:
list.append(num)
except:
break
|
[["-", 0, 656, 0, 1, 0, 662, 12, 680, 0, 45], ["-", 0, 656, 0, 1, 0, 662, 12, 680, 0, 46], ["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 70], ["+", 0, 656, 0, 1, 0, 662, 12, 634, 0, 73]]
| 5
| 41
|
a=[]
while 1:
try:n=int(input());a.append(e)if e else print(a.pop())
except:break
|
a=[]
while 1:
try:n=int(input());a.append(n)if n else print(a.pop())
except:break
|
[["-", 0, 1, 0, 41, 0, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 41, 0, 652, 3, 4, 0, 22], ["-", 0, 246, 8, 196, 0, 1, 0, 41, 0, 22], ["+", 0, 246, 8, 196, 0, 1, 0, 41, 0, 22]]
| 5
| 38
|
import sys
a=[int(i)for i in sys.stdin]
b=[]
print(a)
for j in a:
if j == 0:
print(b.pop())
else:
b.append(j)
|
import sys
a=[int(i)for i in sys.stdin]
b=[]
for j in a:
if j == 0:
print(b.pop())
else:
b.append(j)
|
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
| 5
| 50
|
import sys
a=[map(int,i)for i in sys.stdin]
b=[]
for j in a:
if j == 0:
print(b.pop())
else:
b.append(j)
|
import sys
a=[int(i)for i in sys.stdin]
b=[]
for j in a:
if j == 0:
print(b.pop())
else:
b.append(j)
|
[["-", 0, 1, 0, 662, 12, 658, 8, 652, 63, 22], ["-", 0, 662, 12, 658, 8, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 658, 8, 652, 3, 4, 0, 21], ["+", 0, 662, 12, 658, 8, 652, 3, 4, 0, 24]]
| 5
| 48
|
import sys
lst = []
for line in sys.stdin:
num = int(line.split())
if num == 0:
print(lst.pop())
else:
lst.append(num)
sys.exit(0)
|
import sys
lst = []
for line in sys.stdin:
num = line.strip()
if num == "0":
print(lst.pop())
else:
lst.append(num)
sys.exit(0)
|
[["-", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 12, 652, 3, 4, 0, 652, 63, 319, 319, 22], ["+", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 666, 0, 557, 0, 654], ["+", 8, 196, 0, 57, 15, 666, 0, 557, 0, 655]]
| 5
| 50
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = null;
try {
sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int d = sc.nextInt();
int areaCulcCount = 600 / d;
long sum = 0L;
for (int i = 1; i <= areaCulcCount; i++) {
int x = i * d;
int y = x * x;
sum += y * d;
}
System.out.println(sum);
}
} finally {
sc.close();
}
}
}
|
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = null;
try {
sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int d = sc.nextInt();
int areaCulcCount = (600 - d) / d;
long sum = 0L;
for (int i = 1; i <= areaCulcCount; i++) {
int x = i * d;
int y = x * x;
sum += y * d;
}
System.out.println(sum);
}
} finally {
sc.close();
}
}
}
|
[["+", 0, 503, 49, 200, 51, 16, 31, 23, 0, 24], ["+", 49, 200, 51, 16, 31, 23, 0, 16, 17, 33], ["+", 49, 200, 51, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 503, 49, 200, 51, 16, 31, 23, 0, 25]]
| 3
| 126
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int d = sc.nextInt();
double sum = 0;
for (int i = 1; 600 >= d * (i + 1); i++) {
sum += Math.pow(i * d, 2) * d;
}
System.out.println(sum);
}
sc.close();
}
}
|
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int d = sc.nextInt();
int sum = 0;
for (int i = 1; 600 >= d * (i + 1); i++) {
sum += Math.pow(i * d, 2) * d;
}
System.out.println(sum);
}
sc.close();
}
}
|
[["-", 0, 52, 8, 196, 0, 503, 39, 511, 0, 512], ["+", 0, 52, 8, 196, 0, 503, 39, 506, 0, 507]]
| 3
| 118
|
import java.io.*;
public class Main {
public static void main(String args[]) {
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
String s;
int sum = 0;
while ((s = reader.readLine()) != null) {
int x = Integer.parseInt(s);
for (int i = 1; i * x < 600; i++) {
sum += f(i * x) * x;
}
System.out.println(sum);
}
} catch (IOException e) {
System.out.println(e);
}
}
public static int f(int x) { return x * x; }
}
|
import java.io.*;
public class Main {
public static void main(String args[]) {
try {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
String s;
int sum = 0;
while ((s = reader.readLine()) != null) {
int x = Integer.parseInt(s);
for (int i = 1; i * x < 600; i++) {
sum += f(i * x) * x;
}
System.out.println(sum);
sum = 0;
}
} catch (IOException e) {
System.out.println(e);
}
}
public static int f(int x) { return x * x; }
}
|
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 499], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
| 3
| 145
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt(), ans = 0;
for (int i = 1; i < 600 / n; i++) {
ans += Math.pow(i * n, 2) * n;
System.out.println(ans);
}
}
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt(), ans = 0;
for (int i = 1; i < 600 / n; i++) {
ans += Math.pow(i * n, 2) * n;
}
System.out.println(ans);
}
}
}
|
[["+", 0, 52, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 52, 8, 196, 0, 7, 8, 196, 0, 46]]
| 3
| 100
|
#include <stdio.h>
int main(void) {
int i, a, b, c, d, e;
while (scanf("%d", &a) != EOF) {
b = 600 / a;
int sum = 0;
for (i = 1; i < b; i++) {
e = i * a;
d = e * e;
c = a * d;
sum += c;
}
printf("%d", sum);
if (a == 0) {
break;
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int i, a, b, c, d, e;
while (scanf("%d", &a) != EOF) {
b = 600 / a;
int sum = 0;
for (i = 1; i < b; i++) {
e = i * a;
d = e * e;
c = a * d;
sum += c;
}
printf("%d\n", sum);
if (a == 0) {
break;
}
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 108
|
#include <stdio.h>
int main(void) {
int x, d, area;
while (scanf("%d", &d) != EOF) {
area = 0;
x = d;
while (x < 600) {
area += d * x * x;
x += d;
}
printf("%d", area);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int x, d, area;
while (scanf("%d", &d) != EOF) {
area = 0;
x = d;
while (x < 600) {
area += d * x * x;
x += d;
}
printf("%d\n", area);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 72
|
#include <stdio.h>
int main() {
int d;
while (scanf("%d", &d) != EOF) {
int i, length, sum;
length = 600;
sum = 0;
for (i = 1; i < length / d; i++) {
sum += i * i * d * d;
}
printf("%d", sum * d);
}
return 0;
}
|
#include <stdio.h>
int main() {
int d;
while (scanf("%d", &d) != EOF) {
int i, length, sum;
length = 600;
sum = 0;
for (i = 1; i < length / d; i++) {
sum += i * i * d * d;
}
printf("%d\n", sum * d);
}
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 83
|
#include <stdio.h>
int main(void) {
int d;
int len;
int i;
int s = 0;
int y;
while (scanf("%d", &d)) {
y = d;
len = 600 / d;
for (i = 1; i < len; i++) {
s += d * y * y;
y += d;
}
printf("%d\n", s);
d = 0;
s = 0;
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int d;
int len;
int i;
int s = 0;
int y;
while (scanf("%d", &d) != EOF) {
y = d;
len = 600 / d;
for (i = 1; i < len; i++) {
s += d * y * y;
y += d;
}
printf("%d\n", s);
d = 0;
s = 0;
}
return 0;
}
|
[["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 79], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 12, 22]]
| 0
| 98
|
#include <stdio.h>
int main() {
int n, value;
int i;
while (scanf("%d", &n) != EOF) {
value = 0;
for (i = 0; i < 600; i += n)
value += i * i;
printf("%d\n", value);
}
return 0;
}
|
#include <stdio.h>
int main() {
int n, value;
int i;
while (scanf("%d", &n) != EOF) {
value = 0;
for (i = 0; i < 600; i += n)
value += i * i * n;
printf("%d\n", value);
}
return 0;
}
|
[["+", 0, 7, 8, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 7, 8, 1, 0, 11, 12, 16, 12, 22]]
| 0
| 69
|
#include <stdio.h>
int main() {
int d, x;
int sum = 0;
while (scanf("%d", &d) != EOF) {
for (x = d; x < 600; x += d) {
sum += x * x * d;
}
printf("%d\n", sum);
}
return 0;
}
|
#include <stdio.h>
int main() {
int d, x;
int sum = 0;
while (scanf("%d", &d) != EOF) {
sum = 0;
for (x = d; x < 600; x += d) {
sum += x * x * d;
}
printf("%d\n", sum);
}
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
| 0
| 71
|
#include <stdio.h>
int main(void) {
int num;
while (scanf("%d", &num) != EOF) {
int o = 1, sum = num * num;
while (num * o != 600 - num) {
o++;
sum += num * o * num * o;
}
printf("%d\n", sum);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int num;
while (scanf("%d", &num) != EOF) {
int o = 1, sum = num * num * num;
while (num * o != 600 - num) {
o++;
sum += num * o * num * o * num;
}
printf("%d\n", sum);
}
return 0;
}
|
[["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 48], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
| 0
| 77
|
for x in range(eval(input())):
a = eval(input()) + eval(input())
print(a if len(str(a)) < 80 else "overflow")
|
for x in range(eval(input())):
a = eval(input()) + eval(input())
print(a if len(str(a)) < 81 else "overflow")
|
[["-", 0, 652, 3, 4, 0, 41, 0, 666, 0, 612], ["+", 0, 652, 3, 4, 0, 41, 0, 666, 0, 612]]
| 5
| 46
|
public class Main {
public void run(java.io.InputStream in, java.io.PrintStream out) {
java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
int r, t, i, k;
double x, y;
char[] ch;
String str;
t = 90;
x = 0;
y = 0;
k = 0;
for (; sc.hasNext();) {
str = sc.next();
ch = new char[str.length()];
for (i = 0; i < str.length(); i++) {
ch[i] = str.charAt(i);
if (ch[i] == ',')
k = i;
}
r = readint(ch, 0, k);
x += r * Math.cos(Math.toRadians(t));
y += r * Math.sin(Math.toRadians(t));
t -= readint(ch, k + 1, str.length()) % 360;
}
out.println((int)x + " " + (int)y);
sc.close();
}
public static void main(String[] args) {
(new Main()).run(System.in, System.out);
}
private static int readint(char[] ch, int l, int r) {
int i, d, res, sign;
d = 1;
res = 0;
sign = 1;
if (ch[l] == '-') {
sign = -1;
l++;
}
for (i = r - 1; i >= l; i--) {
res += d * (int)(ch[i] - '0');
d *= 10;
}
return res * sign;
}
}
|
public class Main {
public void run(java.io.InputStream in, java.io.PrintStream out) {
java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
int r, t, i, k;
double x, y;
char[] ch;
String str;
t = 90;
x = 0;
y = 0;
k = 0;
for (; sc.hasNext();) {
str = sc.next();
ch = new char[str.length()];
for (i = 0; i < str.length(); i++) {
ch[i] = str.charAt(i);
if (ch[i] == ',')
k = i;
}
r = readint(ch, 0, k);
x += r * Math.cos(Math.toRadians(t));
y += r * Math.sin(Math.toRadians(t));
t -= readint(ch, k + 1, str.length()) % 360;
}
out.println((int)x);
out.println((int)y);
sc.close();
}
public static void main(String[] args) {
(new Main()).run(System.in, System.out);
}
private static int readint(char[] ch, int l, int r) {
int i, d, res, sign;
d = 1;
res = 0;
sign = 1;
if (ch[l] == '-') {
sign = -1;
l++;
}
for (i = r - 1; i >= l; i--) {
res += d * (int)(ch[i] - '0');
d *= 10;
}
return res * sign;
}
}
|
[["-", 0, 492, 3, 4, 0, 16, 31, 16, 17, 72], ["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 491], ["-", 0, 1, 0, 492, 3, 4, 0, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 492, 3, 4, 0, 25], ["+", 8, 498, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 500, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 0, 131], ["+", 0, 195, 8, 196, 0, 1, 0, 492, 141, 22], ["+", 8, 196, 0, 1, 0, 492, 3, 4, 0, 24]]
| 3
| 374
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int theta = 90;
double x = 0;
double y = 0;
int d = 0;
int a = 0;
while (sc.hasNext()) {
String[] str = sc.nextLine().split(",");
d = Integer.parseInt(str[0]);
a = Integer.parseInt(str[1]);
if (d == 0 && a == 0) {
break;
}
x += (double)d * Math.cos((double)theta * Math.PI / 180);
y += (double)a * Math.sin((double)theta * Math.PI / 180);
theta -= a;
}
System.out.println((int)x + "\n" + (int)y);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int theta = 90;
double x = 0;
double y = 0;
int d = 0;
int a = 0;
while (sc.hasNext()) {
String[] str = sc.nextLine().split(",");
d = Integer.parseInt(str[0]);
a = Integer.parseInt(str[1]);
if (d == 0 && a == 0) {
break;
}
x += (double)d * Math.cos((double)theta * Math.PI / 180);
y += (double)d * Math.sin((double)theta * Math.PI / 180);
theta -= a;
}
System.out.println((int)x + "\n" + (int)y);
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 31, 74, 51, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 51, 22]]
| 3
| 197
|
import java.util.Scanner;
public class Main {
public static class P {
public double x;
public double y;
public P(double x, double y) {
this.x = x;
this.y = y;
}
}
public static P ta(int d, int a) {
double dx = d * Math.sin(a * Math.PI / 180.0);
double dy = d * Math.cos(a * Math.PI / 180.0);
return new P(dx, dy);
}
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
double x = 0.0;
double y = 0.0;
int a0 = 0;
while (sc.hasNext()) {
String[] str = sc.next().split(",");
int d = Integer.parseInt(str[0]);
int a = Integer.parseInt(str[1]);
if (d == 0 && a == 0)
break;
P p = ta(d, a);
x += p.x;
y += p.y;
if (a < 0)
a += 360;
a0 += a;
a0 %= 360;
}
System.out.printf("%d\n%d\n", (int)x, (int)y);
}
}
}
|
import java.util.Scanner;
public class Main {
public static class P {
public double x;
public double y;
public P(double x, double y) {
this.x = x;
this.y = y;
}
}
public static P ta(int d, int a) {
double dx = d * Math.sin(a * Math.PI / 180.0);
double dy = d * Math.cos(a * Math.PI / 180.0);
return new P(dx, dy);
}
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
double x = 0.0;
double y = 0.0;
int a0 = 0;
while (sc.hasNext()) {
String[] str = sc.next().split(",");
int d = Integer.parseInt(str[0]);
int a = Integer.parseInt(str[1]);
if (d == 0 && a == 0)
break;
P p = ta(d, a0);
x += p.x;
y += p.y;
if (a < 0)
a += 360;
a0 += a;
a0 %= 360;
}
System.out.printf("%d\n%d\n", (int)x, (int)y);
}
}
}
|
[["-", 0, 503, 49, 200, 51, 492, 3, 4, 0, 22], ["+", 0, 503, 49, 200, 51, 492, 3, 4, 0, 22]]
| 3
| 279
|
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double[] position = new double[2];
int x = 0;
int theta = 90;
while (true) {
String str = sc.next();
String[] strArr = str.split(",");
x = Integer.parseInt(strArr[0]);
position[0] += x * Math.sin(Math.toRadians(theta));
position[1] += x * Math.cos(Math.toRadians(theta));
theta -= Integer.parseInt(strArr[1]);
if (x == 0 && strArr[1].equals("0")) {
break;
}
}
System.out.println((int)position[0]);
System.out.println((int)position[1]);
}
}
|
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double[] position = new double[2];
int x = 0;
int theta = 90;
while (true) {
String str = sc.next();
String[] strArr = str.split(",");
x = Integer.parseInt(strArr[0]);
position[0] += x * Math.cos(Math.toRadians(theta));
position[1] += x * Math.sin(Math.toRadians(theta));
theta -= Integer.parseInt(strArr[1]);
if (x == 0 && strArr[1].equals("0")) {
break;
}
}
System.out.println((int)position[0]);
System.out.println((int)position[1]);
}
}
|
[["-", 0, 1, 0, 11, 12, 16, 12, 492, 141, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 492, 141, 22]]
| 3
| 205
|
import java.io.*;
public class Main {
public static void main(String[] args) {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s;
String[] t;
int l, kakudo;
int sumkakudo = 0;
double x, y, sumX, sumY;
sumX = 0;
sumY = 0;
try {
while ((s = r.readLine()) != null) {
t = s.split(",");
l = Integer.parseInt(t[0]);
kakudo = Integer.parseInt(t[1]);
if (l == 0 && kakudo == 0) {
break;
}
y = l * Math.sin(Math.toRadians(90 - sumkakudo));
x = l * Math.cos(Math.toRadians(90 - sumkakudo));
sumX += x;
sumY += y;
sumkakudo += kakudo;
}
System.out.println((int)sumX + " " + (int)sumY);
sumkakudo = 0;
sumX = 0;
sumY = 0;
} catch (IOException e) {
System.out.println(e);
}
}
}
|
import java.io.*;
public class Main {
public static void main(String[] args) {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String s;
String[] t;
int l, kakudo;
int sumkakudo = 0;
double x, y, sumX, sumY;
sumX = 0;
sumY = 0;
try {
while ((s = r.readLine()) != null) {
t = s.split(",");
l = Integer.parseInt(t[0]);
kakudo = Integer.parseInt(t[1]);
if (l == 0 && kakudo == 0) {
break;
}
y = l * Math.sin(Math.toRadians(90 - sumkakudo));
x = l * Math.cos(Math.toRadians(90 - sumkakudo));
sumX += x;
sumY += y;
sumkakudo += kakudo;
}
System.out.println((int)sumX + "\n" + (int)sumY);
sumkakudo = 0;
sumX = 0;
sumY = 0;
} catch (IOException e) {
System.out.println(e);
}
}
}
|
[["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 491], ["+", 3, 4, 0, 16, 31, 16, 12, 5, 0, 44]]
| 3
| 239
|
#include <math.h>
#include <stdio.h>
int main() {
int d, r;
double x, y;
double rad = 90;
int a, b;
while (scanf("%d,%d", &d, &r) != EOF) {
if (!d && !r)
break;
x += d * cos(rad * M_PI / 180);
y += d * sin(rad * M_PI / 180);
rad -= r;
}
a = (int)x;
b = (int)y;
printf("%d %d\n", a, b);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int d, r;
double x = 0, y = 0;
double rad = 90;
int a, b;
while (scanf("%d,%d", &d, &r) != EOF) {
if (!d && !r)
break;
x += d * cos(rad * M_PI / 180);
y += d * sin(rad * M_PI / 180);
rad -= r;
}
a = (int)x;
b = (int)y;
printf("%d\n%d\n", a, b);
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 118
|
#include <math.h>
#include <stdio.h>
int main(void) {
int d, t, deg;
double rad, x, y;
deg = 90;
x = y = 0;
while (scanf("%d,%d", &d, &t) != EOF && d && t) {
rad = deg * M_PI / 180;
x += cos(rad) * d;
y += sin(rad) * d;
deg = (deg - t + 360) % 360;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int d, t, deg;
double rad, x, y;
deg = 90;
x = y = 0;
while (scanf("%d,%d", &d, &t) != EOF && (d || t)) {
rad = deg * M_PI / 180;
x += cos(rad) * d;
y += sin(rad) * d;
deg = (deg - t + 360) % 360;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["+", 0, 52, 15, 23, 0, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 23, 0, 16, 12, 23, 0, 25]]
| 0
| 119
|
#include <math.h>
#include <stdio.h>
#define PI 3.14159265358
int main(void) {
double x, y;
int int_x, int_y;
int angle_sum, s, a;
x = 0;
y = 0;
angle_sum = 90;
while (1) {
scanf("%d,%d", &s, &a);
if (s != 0 && a != 0) {
break;
}
x += s * cos(angle_sum * PI / 180.0);
y += s * sin(angle_sum * PI / 180.0);
angle_sum -= a;
}
int_x = x;
int_y = y;
printf("%d\n%d\n", int_x, int_y);
return (0);
}
|
#include <math.h>
#include <stdio.h>
#define PI 3.14159265358
int main(void) {
double x, y;
int int_x, int_y;
int angle_sum, s, a;
x = 0;
y = 0;
angle_sum = 90;
while (1) {
scanf("%d,%d", &s, &a);
if (s == 0 && a == 0) {
break;
}
x += s * cos(angle_sum * PI / 180.0);
y += s * sin(angle_sum * PI / 180.0);
angle_sum -= a;
}
int_x = x;
int_y = y;
printf("%d\n%d\n", int_x, int_y);
return (0);
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 23, 0, 16, 12, 16, 17, 60]]
| 0
| 133
|
#include <math.h>
#include <stdio.h>
int main() {
double l, r = 90, nr;
double pos_x = 0, pos_y = 0;
while (1) {
scanf("%lf,%lf", &l, &nr);
;
pos_x += l * cos(r / 180 * M_PI);
pos_y += l * sin(r / 180 * M_PI);
r += nr;
if (l == 0 && nr == 0)
break;
}
printf("%d\n%d\n", (int)pos_x, (int)pos_y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
double l, r = 90, nr;
double pos_x = 0, pos_y = 0;
while (1) {
scanf("%lf,%lf", &l, &nr);
;
pos_x -= l * cos(r / 180 * M_PI);
pos_y += l * sin(r / 180 * M_PI);
r += nr;
if (l == 0 && nr == 0)
break;
}
printf("%d\n%d\n", (int)pos_x, (int)pos_y);
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110]]
| 0
| 113
|
#include <math.h>
#include <stdio.h>
#define PI 3.1415926
int main(void) {
double x = 0, y = 0;
int z, turn;
double angle = 0;
while (scanf("%d,%d", &z, &turn) != EOF) {
if (z == 0 && turn == 0)
break;
x += cos(PI * angle / 180.0) * z;
y += sin(PI * angle / 180.0) * z;
angle += turn;
}
printf("%d %d", (int)y, (int)x);
return 0;
}
|
#include <math.h>
#include <stdio.h>
#define PI 3.1415926
int main(void) {
double x = 0, y = 0;
int z, turn;
double angle = 0;
while (scanf("%d,%d", &z, &turn) != EOF) {
if (z == 0 && turn == 0)
break;
x += cos(PI * angle / 180.0) * z;
y += sin(PI * angle / 180.0) * z;
angle += turn;
}
printf("%d\n%d\n", (int)y, (int)x);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 114
|
#include <math.h>
#include <stdio.h>
#define pi 3.14159265358
int main() {
double x, y, R = 90;
int d, r;
while (1) {
scanf("%d,%d", &d, &r);
if (d == 0 && r == 0)
break;
x += d * cos(R / 180.0 * pi);
y += d * sin(R / 180.0 * pi);
R += r;
// printf("%lf %lf\n",cos(R/180.0*pi),sin(R/180.0*pi));
// printf("%d %d\n",(int)x,(int)y);
}
printf("%d %d\n", (int)x, (int)-y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
#define pi 3.14159265358
int main() {
double x, y, R = 90;
int d, r;
while (1) {
scanf("%d,%d", &d, &r);
if (d == 0 && r == 0)
break;
x += d * cos(R / 180.0 * pi);
y += d * sin(R / 180.0 * pi);
R += r;
// printf("%lf %lf\n",cos(R/180.0*pi),sin(R/180.0*pi));
// printf("%d %d\n",(int)x,(int)y);
}
printf("%d\n%d\n", (int)-x, (int)y);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 2, 3, 4, 0, 74, 51, 91, 17, 33], ["-", 0, 2, 3, 4, 0, 74, 51, 91, 17, 33]]
| 0
| 112
|
#include <math.h>
#include <stdio.h>
int main(void) {
int distance = 0, angle = 90, rotate;
double x = 0, y = 0, Pi = 3.141592;
while (1) {
scanf("%d,", &distance);
x += distance * cos(angle * Pi / 180);
y += distance * sin(angle * Pi / 180);
scanf("%d", &rotate);
if (distance == 0 && rotate == 0)
break;
angle -= rotate;
}
printf("%d %d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int distance = 0, angle = 90, rotate;
double x = 0, y = 0, Pi = 3.141592;
while (1) {
scanf("%d,", &distance);
x += distance * cos(angle * Pi / 180);
y += distance * sin(angle * Pi / 180);
scanf("%d", &rotate);
if (distance == 0 && rotate == 0)
break;
angle -= rotate;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 124
|
#include <math.h>
#include <stdio.h>
int main(void) {
int w, a;
double x = 0.0, y = 0.0;
double age = 90.0;
double r;
while (1) {
scanf("%d,%d", &w, &a);
if (w == 0 && a == 0)
break;
r = (age / 180.0 * M_PI);
x += cos(r) * w;
y += sin(r) * w;
age -= a;
}
printf("%d\n%d\n", x, y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int w, a;
double x = 0.0, y = 0.0;
double age = 90.0;
double r;
while (1) {
scanf("%d,%d", &w, &a);
if (w == 0 && a == 0)
break;
r = (age / 180.0 * M_PI);
x += cos(r) * w;
y += sin(r) * w;
age -= a;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["+", 0, 1, 0, 2, 3, 4, 0, 74, 0, 24], ["+", 0, 2, 3, 4, 0, 74, 39, 77, 39, 40], ["+", 0, 1, 0, 2, 3, 4, 0, 74, 0, 25]]
| 0
| 113
|
#include <math.h>
#include <stdio.h>
int main(void) {
int aa = 90, d, a;
float x = 0, y = 0;
while (1) {
scanf("%d,%d", &d, &a);
if (d == 0 && a == 0) {
break;
}
y = y + (float)d * sin(aa * 3.14159265358979 / 180);
x = x + (float)d * cos(aa * 3.14159265358979 / 180);
aa = aa - a;
}
printf("%d %d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
int aa = 90, d, a;
float x = 0, y = 0;
while (1) {
scanf("%d,%d", &d, &a);
if (d == 0 && a == 0) {
break;
}
y = y + (float)d * sin(aa * 3.14159265358979 / 180);
x = x + (float)d * cos(aa * 3.14159265358979 / 180);
aa = aa - a;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 125
|
#include <math.h>
#include <stdio.h>
int main() {
int r, dc, c = 90;
double x = 0, y = 0;
while (scanf("%d,%d", &r, &dc), (r && dc)) {
x += r * cos(c * M_PI / 180);
y += r * sin(c * M_PI / 180);
c -= dc;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int r, dc, c = 90;
double x = 0, y = 0;
while (scanf("%d,%d", &r, &dc), (r || dc)) {
x += r * cos(c * M_PI / 180);
y += r * sin(c * M_PI / 180);
c -= dc;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 15, 23, 0, 34, 12, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 34, 12, 23, 0, 16, 17, 106]]
| 0
| 104
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x = 0, y = 0, v = 90;
double line, angle;
while (scanf("%lf,%lf", &line, &angle), line && angle) {
x += line * cos(M_PI * v / 180);
y += line * sin(M_PI * v / 180);
v -= angle;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main(void) {
double x = 0, y = 0, v = 90;
double line, angle;
while (scanf("%lf,%lf", &line, &angle), line || angle) {
x += line * cos(M_PI * v / 180);
y += line * sin(M_PI * v / 180);
v -= angle;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 0, 52, 15, 23, 0, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 23, 0, 34, 12, 16, 17, 106]]
| 0
| 103
|
#include <math.h>
#include <stdio.h>
double x, y, a;
int main() {
double mov, dir;
while (scanf("%lf,%lf", &mov, &dir), mov, dir) {
x += mov * sin(a * M_PI / 180);
y += mov * cos(a * M_PI / 180);
a += dir;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
double x, y, a;
int main() {
double mov, dir;
while (scanf("%lf,%lf", &mov, &dir), mov || dir) {
x += mov * sin(a * M_PI / 180);
y += mov * cos(a * M_PI / 180);
a += dir;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 0, 52, 15, 23, 0, 34, 12, 34, 0, 21], ["+", 0, 52, 15, 23, 0, 34, 12, 16, 17, 106]]
| 0
| 96
|
#include <math.h>
#include <stdio.h>
int main() {
int r, p, t;
double x, y;
scanf("%d,%d", &r, &p);
y = r;
t = p;
while (1) {
scanf("%d,%d", &r, &p);
if (r == 0 && p == 0)
break;
y += r * sin(M_PI_2 - t * M_PI / 180);
x += r * cos(M_PI_2 - t * M_PI / 180);
t = p;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
int r, p, t;
double x, y;
scanf("%d,%d", &r, &p);
y = r;
t = p;
while (1) {
scanf("%d,%d", &r, &p);
if (r == 0 && p == 0)
break;
y += r * sin(M_PI_2 - t * M_PI / 180);
x += r * cos(M_PI_2 - t * M_PI / 180);
t += p;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107]]
| 0
| 131
|
#include <math.h>
#include <stdio.h>
int main() {
double x = 0.0, y = 0.0;
int theta = 90;
int a, b;
for (;;) {
scanf("%d,%d", &a, &b);
if (a == 0 && b == 0)
break;
x += a * cos(theta * M_PI / 180);
y += a * sin(theta * M_PI / 180);
theta -= b;
}
printf("%d,%d\n", (int)x, (int)y);
return 0;
}
|
#include <math.h>
#include <stdio.h>
int main() {
double x = 0.0, y = 0.0;
int theta = 90;
int a, b;
for (;;) {
scanf("%d,%d", &a, &b);
if (a == 0 && b == 0)
break;
x += a * cos(theta * M_PI / 180);
y += a * sin(theta * M_PI / 180);
theta -= b;
}
printf("%d\n%d\n", (int)x, (int)y);
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 0
| 112
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.14159265358979323
// int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
// void quick(int *,long long,long long);
// int comp(char *a,char *b);
int main() {
double x, y;
int a, b, r, i;
x = 0;
y = 0;
r = 90;
scanf("%d,%d", &a, &b);
while (a != 0 || b != 0) {
x += a * cos((double)r / 180 * PI);
y += a * sin((double)r / 180 * PI);
r += b;
scanf("%d,%d", &a, &b);
;
}
printf("%d\n%d\n", (int)x, (int)y);
// for(i=0;i<=1000000000;i++);
return 0;
}
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.14159265358979323
// int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
// void quick(int *,long long,long long);
// int comp(char *a,char *b);
int main() {
double x, y;
int a, b, r, i;
x = 0;
y = 0;
r = 90;
scanf("%d,%d", &a, &b);
while (a != 0 || b != 0) {
x += a * cos((double)r / 180 * PI);
y += a * sin((double)r / 180 * PI);
r -= b;
scanf("%d,%d", &a, &b);
;
}
printf("%d\n%d\n", (int)x, (int)y);
// for(i=0;i<=1000000000;i++);
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110]]
| 0
| 143
|
// ヘッダファイルのインクルード
#include <math.h>
#include <stdio.h>
// マクロ定義
#define X 0
#define Y 1
#define X_AND_Y 2
#define NORTH 90 //度表現
#define compile 0 //デバッグ用,0:実装版,1:デバッグ版
// 関数のプロトタイプ宣言
double func_cal_rad(double angle); //度からラジアンへ変換する関数
double func_cal_x(double edge, double angle_r, double x); // x座標を計算する関数
double func_cal_y(double edge, double angle_r, double y); // y座標を計算する関数
void func_output(double array[], int n); //結果の出力を行う関数
main() {
double input_l = 0,
input_t = 0; //入力代入用の変数,input_l:進む距離,input_t:回転する角度
double turn = 0; //回転角代入用の変数,turn:現在の回転角
double t_rad = 0; //回転角代入用の変数,t_rad:回転角を[rad]に変換
double point[X_AND_Y] = {0, 0}; //座標代入用の変数
turn = NORTH; //問題の仕様では最初の角度はx軸に対して垂直(角度は90°)になる
scanf("%lf,%lf", &input_l, &input_t); //入力の取得
#if compile == 1 //デバッグ用
puts("");
#endif
while ((0 != input_l) && (0 != input_t)) // input_l,input_tの2値が0でないとき
{
t_rad = func_cal_rad(turn); //度表記をラジアン表記に変換
point[X] = func_cal_x(input_l, t_rad, point[X]); // x座標の計算
point[Y] = func_cal_y(input_l, t_rad, point[Y]); // y座標の計算
#if compile == 1 //デバッグ用
printf("point[X] = %lf point[Y] = %lf\n", point[X], point[Y]);
#endif
turn -= input_t; //現在の角度の値input_tをturnに代入
input_l = 0, input_t = 0; //入力前に一度初期化する
scanf("%lf,%lf", &input_l, &input_t); //入力の取得
}
func_output(point, X_AND_Y); //結果の出力
return 0;
}
double func_cal_rad(double angle_d) //度からラジアンへ変換する関数
{
double rad = 0;
rad = (angle_d * M_PI) / 180; //角の変換公式を使用,要インクルードmath.h
return rad;
}
double func_cal_x(double edge, double angle_r, double x) // x座標を計算する関数
{
double p_x = 0;
p_x =
(double)(edge * cos(angle_r)) +
x; //移動先の座標から移動元の座標を引いた長さが移動先のx座標,要インクルードmath.h
return p_x;
}
double func_cal_y(double edge, double angle_r, double y) // y座標を計算する関数
{
double p_y = 0;
p_y =
(double)(edge * sin(angle_r)) +
y; //移動先の座標から移動元の座標を引いた長さが移動先のy座標,要インクルードmath.h
return p_y;
}
void func_output(double array[], int n) //結果の出力を行う関数
{
int i = 0;
for (i = 0; i < n; i++) //出力をループさせる
{
#if compile == 0 //実装版
if (0 > array[i]) // array[i]のi番目の要素が0未満の実数の場合
{
array[i] = ceil(array[i]); //小数点以下切り上げを行う,要インクルードmath.h
} else // array[i]のi番目の要素が0より大きい実数の場合
{
array[i] =
floor(array[i]); //小数点以下切り捨てを行う,要インクルードmath.h
}
#endif
#if compile == 0 //実装版
printf("%.0lf\n",
array[i]); // 1回目のループでx座標,2回目のループでy座標をそれぞれ表示
#elif compile == 1 //デバッグ版
printf("%.0lf\n",
array[i]); // 1回目のループでx座標,2回目のループでy座標をそれぞれ表示
#endif
}
}
|
// ヘッダファイルのインクルード
#include <math.h>
#include <stdio.h>
// マクロ定義
#define X 0
#define Y 1
#define X_AND_Y 2
#define NORTH 90 //度表現
#define compile 0 //デバッグ用,0:実装版,1:デバッグ版
// 関数のプロトタイプ宣言
double func_cal_rad(double angle); //度からラジアンへ変換する関数
double func_cal_x(double edge, double angle_r, double x); // x座標を計算する関数
double func_cal_y(double edge, double angle_r, double y); // y座標を計算する関数
void func_output(double array[], int n); //結果の出力を行う関数
main() {
double input_l = 0,
input_t = 0; //入力代入用の変数,input_l:進む距離,input_t:回転する角度
double turn = 0; //回転角代入用の変数,turn:現在の回転角
double t_rad = 0; //回転角代入用の変数,t_rad:回転角を[rad]に変換
double point[X_AND_Y] = {0, 0}; //座標代入用の変数
turn = NORTH; //問題の仕様では最初の角度はx軸に対して垂直(角度は90°)になる
scanf("%lf,%lf", &input_l, &input_t); //入力の取得
#if compile == 1 //デバッグ用
puts("");
#endif
while ((0 != input_l) || (0 != input_t)) // input_l,input_tの2値が0でないとき
{
t_rad = func_cal_rad(turn); //度表記をラジアン表記に変換
point[X] = func_cal_x(input_l, t_rad, point[X]); // x座標の計算
point[Y] = func_cal_y(input_l, t_rad, point[Y]); // y座標の計算
#if compile == 1 //デバッグ用
printf("point[X] = %lf point[Y] = %lf\n", point[X], point[Y]);
#endif
turn -= input_t; //現在の角度の値input_tをturnに代入
input_l = 0, input_t = 0; //入力前に一度初期化する
scanf("%lf,%lf", &input_l, &input_t); //入力の取得
}
func_output(point, X_AND_Y); //結果の出力
return 0;
}
double func_cal_rad(double angle_d) //度からラジアンへ変換する関数
{
double rad = 0;
rad = (angle_d * M_PI) / 180; //角の変換公式を使用,要インクルードmath.h
return rad;
}
double func_cal_x(double edge, double angle_r, double x) // x座標を計算する関数
{
double p_x = 0;
p_x =
(double)(edge * cos(angle_r)) +
x; //移動先の座標から移動元の座標を引いた長さが移動先のx座標,要インクルードmath.h
return p_x;
}
double func_cal_y(double edge, double angle_r, double y) // y座標を計算する関数
{
double p_y = 0;
p_y =
(double)(edge * sin(angle_r)) +
y; //移動先の座標から移動元の座標を引いた長さが移動先のy座標,要インクルードmath.h
return p_y;
}
void func_output(double array[], int n) //結果の出力を行う関数
{
int i = 0;
for (i = 0; i < n; i++) //出力をループさせる
{
#if compile == 0 //実装版
if (0 > array[i]) // array[i]のi番目の要素が0未満の実数の場合
{
array[i] = ceil(array[i]); //小数点以下切り上げを行う,要インクルードmath.h
} else // array[i]のi番目の要素が0より大きい実数の場合
{
array[i] =
floor(array[i]); //小数点以下切り捨てを行う,要インクルードmath.h
}
#endif
#if compile == 0 //実装版
printf("%.0lf\n",
array[i]); // 1回目のループでx座標,2回目のループでy座標をそれぞれ表示
#elif compile == 1 //デバッグ版
printf("%lf\n",
array[i]); // 1回目のループでx座標,2回目のループでy座標をそれぞれ表示
#endif
}
}
|
[["-", 0, 9, 0, 52, 15, 23, 0, 16, 17, 98], ["+", 0, 9, 0, 52, 15, 23, 0, 16, 17, 106], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 0
| 504
|
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
const int MOD = 1000000007;
const int INF = 1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps = 1e-10;
const int inf = 1e9;
typedef pair<int, int> P;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
class Point {
public:
double x, y;
Point(double x, double y) : x(x), y(y) {}
Point operator+(const Point &p) { return Point(x + p.x, y + p.y); }
Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
Point operator*(double k) { return Point(x * k, y * k); }
Point operator/(double k) { return Point(x / k, y / k); }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
}
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
};
typedef Point Vector;
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
double norm(Point a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a)); }
struct Segment {
Point p1, p2;
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
typedef Segment Line;
class Circle {
public:
Point c;
double r;
Circle(Point c, double r) : c(c), r(r) {}
};
typedef vector<Point> Polygon;
bool isorthogonal(Vector a, Vector b) { return fabs(dot(a, b) - 0.0) < eps; }
bool isparallel(Vector a, Vector b) { return fabs(cross(a, b) - 0.0) < eps; }
Point project(Segment s, Point p) {
Vector base = s.p2 - s.p1;
double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
double getdistance(Point a, Point b) { return abs(a - b); }
double getdistanceLP(Line l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
double getdistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return abs(p - s.p2);
return getdistanceLP(s, p);
}
int ccw(Point p0, Point p1, Point p2) {
Vector a = p1 - p0;
Vector b = p2 - p0;
if (cross(a, b) > eps)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -eps)
return CLOCKWISE;
if (dot(a, b) < -eps)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point getcrosspoint(Segment s1, Segment s2) {
Vector base = s2.p2 - s2.p1;
double d1 = abs(cross(base, s1.p1 - s2.p1));
double d2 = abs(cross(base, s1.p2 - s2.p1));
double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
double getdistanceSS(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min(min(getdistanceSP(s1, s2.p1), getdistanceSP(s1, s2.p2)),
min(getdistanceSP(s2, s1.p1), getdistanceSP(s2, s1.p2)));
}
pair<Point, Point> getcrosspoints(Circle c, Line l) {
// assert(intersect(c,l));
Vector pr = project(l, c.c);
Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
double base = sqrt(c.r * c.r - norm(pr - c.c));
return make_pair(pr + e * base, pr - e * base);
}
double arg(Vector p) { return atan2(p.y, p.x); }
Vector polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
pair<Point, Point> getcrosspoints(Circle c1, Circle c2) {
double d = abs(c1.c - c2.c);
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
int contains(Polygon g, Point p) {
int n = g.size();
bool x = false;
for (int i = 0; i < n; i++) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
if (abs(cross(a, b)) < eps && dot(a, b) < eps)
return 1;
if (a.y > b.y)
swap(a, b);
if (a.y < eps && eps < b.y && cross(a, b) > eps)
x = !x;
}
return (x ? 2 : 0);
}
Polygon andrewscan(Polygon s) {
Polygon u, l;
if (s.size() < 3)
return s;
sort(s.begin(), s.end());
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int n = u.size(); n >= 2 && ccw(u[n - 2], u[n - 1], s[i]) != CLOCKWISE;
n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int n = l.size(); n >= 2 && ccw(l[n - 2], l[n - 1], s[i]) != CLOCKWISE;
n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(l.begin(), l.end());
for (int i = u.size() - 2; i >= 1; i--)
l.push_back(u[i]);
return l;
}
int main(int argc, char const *argv[]) {
char ch;
double dis, rote;
double angle = 90.0;
double lastx = 0.0, lasty = 0.0;
while (cin >> dis >> ch >> rote && dis) {
lastx += cos(angle * M_PI / 180.0) * dis;
lasty += sin(angle * M_PI / 180.0) * dis;
angle -= rote;
}
cout << int(lastx) << ' ' << int(lasty) << endl;
}
|
#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
const int MOD = 1000000007;
const int INF = 1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps = 1e-10;
const int inf = 1e9;
typedef pair<int, int> P;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
class Point {
public:
double x, y;
Point(double x, double y) : x(x), y(y) {}
Point operator+(const Point &p) { return Point(x + p.x, y + p.y); }
Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
Point operator*(double k) { return Point(x * k, y * k); }
Point operator/(double k) { return Point(x / k, y / k); }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < eps && fabs(y - p.y) < eps;
}
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
};
typedef Point Vector;
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
double norm(Point a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a)); }
struct Segment {
Point p1, p2;
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
typedef Segment Line;
class Circle {
public:
Point c;
double r;
Circle(Point c, double r) : c(c), r(r) {}
};
typedef vector<Point> Polygon;
bool isorthogonal(Vector a, Vector b) { return fabs(dot(a, b) - 0.0) < eps; }
bool isparallel(Vector a, Vector b) { return fabs(cross(a, b) - 0.0) < eps; }
Point project(Segment s, Point p) {
Vector base = s.p2 - s.p1;
double r = dot(p - s.p1, base) / norm(base);
return s.p1 + base * r;
}
Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; }
double getdistance(Point a, Point b) { return abs(a - b); }
double getdistanceLP(Line l, Point p) {
return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}
double getdistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return abs(p - s.p1);
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return abs(p - s.p2);
return getdistanceLP(s, p);
}
int ccw(Point p0, Point p1, Point p2) {
Vector a = p1 - p0;
Vector b = p2 - p0;
if (cross(a, b) > eps)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -eps)
return CLOCKWISE;
if (dot(a, b) < -eps)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point getcrosspoint(Segment s1, Segment s2) {
Vector base = s2.p2 - s2.p1;
double d1 = abs(cross(base, s1.p1 - s2.p1));
double d2 = abs(cross(base, s1.p2 - s2.p1));
double t = d1 / (d1 + d2);
return s1.p1 + (s1.p2 - s1.p1) * t;
}
double getdistanceSS(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min(min(getdistanceSP(s1, s2.p1), getdistanceSP(s1, s2.p2)),
min(getdistanceSP(s2, s1.p1), getdistanceSP(s2, s1.p2)));
}
pair<Point, Point> getcrosspoints(Circle c, Line l) {
// assert(intersect(c,l));
Vector pr = project(l, c.c);
Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
double base = sqrt(c.r * c.r - norm(pr - c.c));
return make_pair(pr + e * base, pr - e * base);
}
double arg(Vector p) { return atan2(p.y, p.x); }
Vector polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
pair<Point, Point> getcrosspoints(Circle c1, Circle c2) {
double d = abs(c1.c - c2.c);
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
int contains(Polygon g, Point p) {
int n = g.size();
bool x = false;
for (int i = 0; i < n; i++) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
if (abs(cross(a, b)) < eps && dot(a, b) < eps)
return 1;
if (a.y > b.y)
swap(a, b);
if (a.y < eps && eps < b.y && cross(a, b) > eps)
x = !x;
}
return (x ? 2 : 0);
}
Polygon andrewscan(Polygon s) {
Polygon u, l;
if (s.size() < 3)
return s;
sort(s.begin(), s.end());
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int n = u.size(); n >= 2 && ccw(u[n - 2], u[n - 1], s[i]) != CLOCKWISE;
n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int n = l.size(); n >= 2 && ccw(l[n - 2], l[n - 1], s[i]) != CLOCKWISE;
n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(l.begin(), l.end());
for (int i = u.size() - 2; i >= 1; i--)
l.push_back(u[i]);
return l;
}
int main(int argc, char const *argv[]) {
char ch;
double dis, rote;
double angle = 90.0;
double lastx = 0.0, lasty = 0.0;
while (cin >> dis >> ch >> rote && dis) {
lastx += cos(angle * M_PI / 180.0) * dis;
lasty += sin(angle * M_PI / 180.0) * dis;
angle -= rote;
}
cout << int(lastx) << endl;
cout << int(lasty) << endl;
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 104], ["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 125], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 31, 22]]
| 1
| 1,932
|
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;
template <class T, class U> void assign(V<T> &v, int n, const U &a) {
v.assign(n, a);
}
template <class T, class... Args>
void assign(V<T> &v, int n, const Args &...args) {
v.resize(n);
for (auto &&e : v)
assign(e, args...);
}
constexpr long double pi = acos(-1L);
V<string> split(const string &s, char c) {
V<string> res;
stringstream ss(s);
string t;
while (getline(ss, t, c))
res.push_back(t);
return res;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long double x = 0, y = 0;
int th = 90;
string s;
while (getline(cin, s)) {
auto ss = split(s, ',');
int d = stoi(ss[0]), a = stoi(ss[1]);
if (d == 0)
break;
x += d * cos(th * pi / 180);
y += d * sin(th * pi / 180);
th -= a;
}
cout << static_cast<int>(x) << ' ' << static_cast<int>(y) << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;
template <class T, class U> void assign(V<T> &v, int n, const U &a) {
v.assign(n, a);
}
template <class T, class... Args>
void assign(V<T> &v, int n, const Args &...args) {
v.resize(n);
for (auto &&e : v)
assign(e, args...);
}
constexpr long double pi = acos(-1L);
V<string> split(const string &s, char c) {
V<string> res;
stringstream ss(s);
string t;
while (getline(ss, t, c))
res.push_back(t);
return res;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long double x = 0, y = 0;
int th = 90;
string s;
while (getline(cin, s)) {
auto ss = split(s, ',');
int d = stoi(ss[0]), a = stoi(ss[1]);
if (d == 0)
break;
x += d * cos(th * pi / 180);
y += d * sin(th * pi / 180);
th -= a;
}
cout << static_cast<int>(x) << '\n';
cout << static_cast<int>(y) << '\n';
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 103, 0, 125], ["+", 8, 9, 0, 1, 0, 16, 12, 103, 0, 44], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 31, 22]]
| 1
| 358
|
#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;
const double PI = 3.141592653589793238462643383279502884L;
int main(int argc, char **argv) {
int degree = 90;
int d, t;
char c;
complex<double> v(0, 0);
while (cin >> d >> c >> t) {
if (!d && !t)
break;
auto next = polar((double)d, degree * PI / 180.0);
v += next;
degree = (degree - t) % 360;
}
printf("%d %d\n", (int)v.real(), (int)v.imag());
return 0;
}
|
#include <complex>
#include <cstdio>
#include <iostream>
using namespace std;
const double PI = 3.141592653589793238462643383279502884L;
int main(int argc, char **argv) {
int degree = 90;
int d, t;
char c;
complex<double> v(0, 0);
while (cin >> d >> c >> t) {
if (!d && !t)
break;
auto next = polar((double)d, degree * PI / 180.0);
v += next;
degree = (degree - t) % 360;
}
printf("%d\n%d\n", (int)v.real(), (int)v.imag());
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 135
|
#include <complex>
#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFFINES
#include <cmath>
using namespace std;
typedef complex<double> P;
double convert(double angle) { return ((M_PI * (angle / 180.0))); }
P now(0, 0);
double angle = 0;
int main(void) {
int fd, spin;
while (scanf("%d,%d", &fd, &spin), fd + spin != 0) {
double nextx = now.real() + fd * cos(convert(angle)),
nexty = now.imag() + fd * sin(convert(angle));
now = P(nextx, nexty);
angle += spin;
}
cout << (int)now.real() << endl << (int)now.imag() << endl;
return (0);
}
|
#include <complex>
#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFFINES
#include <cmath>
using namespace std;
typedef complex<double> P;
double convert(double angle) { return ((M_PI * (angle / 180.0))); }
P now(0, 0);
double angle = 0;
int main(void) {
int fd, spin;
while (scanf("%d,%d", &fd, &spin), fd + spin != 0) {
double nextx = now.real() + fd * sin(convert(angle)),
nexty = now.imag() + fd * cos(convert(angle));
now = P(nextx, nexty);
angle += spin;
}
cout << (int)now.real() << endl << (int)now.imag() << endl;
return (0);
}
|
[["-", 49, 50, 51, 16, 12, 16, 12, 2, 63, 22], ["+", 49, 50, 51, 16, 12, 16, 12, 2, 63, 22]]
| 1
| 169
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int r, deg, theta;
double x, y, rad;
x = 0.0;
y = 0.0;
theta = 0;
rad = M_PI / 180;
do {
scanf("%d, %d", &r, °);
if (r == 0 && deg == 0)
break;
x += r * cos(theta * rad);
y += r * sin(theta * rad);
theta = theta + deg;
} while (1);
cout << (int)x << endl << (int)y << endl;
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int r, deg, theta;
double x, y, rad;
x = 0.0;
y = 0.0;
theta = 0;
rad = M_PI / 180;
do {
scanf("%d, %d", &r, °);
if (r == 0 && deg == 0)
break;
x += r * cos(theta * rad);
y += r * sin(theta * rad);
theta = theta + deg;
} while (1);
cout << (int)y << endl << (int)x << endl;
return 0;
}
|
[["-", 31, 16, 31, 16, 31, 16, 12, 74, 51, 22], ["+", 31, 16, 31, 16, 31, 16, 12, 74, 51, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 74, 51, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 74, 51, 22]]
| 1
| 128
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double nx = 0, ny = 0, x, y, ro = 0;
while (true) {
cin >> x;
cin.ignore();
cin >> y;
if (x == 0 && y == 0)
break;
ny += x * sin(ro / 180 * M_PI);
nx += x * cos(ro / 180 * M_PI);
ro += y;
// cout<<nx<<" "<<ny<<endl;
}
cout << (int)nx << endl << (int)ny << endl;
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double nx = 0, ny = 0, x, y, ro = 90;
while (true) {
cin >> x;
cin.ignore();
cin >> y;
if (x == 0 && y == 0)
break;
ny += x * sin(ro / 180 * M_PI);
nx += x * cos(ro / 180 * M_PI);
ro -= y;
// if(ro<0)ro=360-abs(ro);
// cout<<nx<<" "<<ny<<endl;
}
cout << (int)nx << endl << (int)ny << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110]]
| 1
| 113
|
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double x = 0, y = 0, a, b, now = 90;
char c;
while (cin >> a >> c >> b, a || b) {
x += a * cos(M_PI * now / 180);
y += a * sin(M_PI * now / 180);
now = now - b;
}
if (x >= 0)
x = floor(x);
else if (x < 0)
x = ceil(x);
if (y >= 0)
y = floor(y);
else if (y < 0)
y = ceil(y);
cout << x << " " << y << endl;
}
|
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
using namespace std;
int main() {
double x = 0, y = 0, a, b, now = 90;
char c;
while (cin >> a >> c >> b, a || b) {
x += a * cos(M_PI * now / 180);
y += a * sin(M_PI * now / 180);
now = now - b;
}
if (x >= 0)
x = floor(x);
else if (x < 0)
x = ceil(x);
if (y >= 0)
y = floor(y);
else if (y < 0)
y = ceil(y);
cout << x << endl;
cout << y << endl;
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 31, 22]]
| 1
| 150
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template <class T, class S> inline bool minup(T &m, S x) {
return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, S x) {
return m < (T)x ? (m = (T)x, true) : false;
}
const int INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;
struct Point : public complex<double> {
public:
Point() {
this->real(0);
this->imag(0);
}
Point(const double &x, const double &y) {
this->real(x);
this->imag(y);
}
Point(const complex<double> w) {
this->real(w.real());
this->imag(w.imag());
}
inline double dot(Point p) { return (conj(*this) * p).real(); } // ??????
inline double det(Point p) { return (conj(*this) * p).imag(); } // ??????
};
namespace std {
bool operator<(const Point &a, const Point &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
typedef vector<Point> Polygon;
#define currPoint(P, i) P[i]
#define nextPoint(P, i) P[(i + 1) % P.size()]
template <typename T> ostream &operator<<(ostream &r, const vector<T> t) {
vrep(v, t) r << *v << (v + 1 == t.end() ? "" : " ");
return r;
}
template <typename T>
ostream &operator<<(ostream &r, const pair<vector<T>, int> p) {
int n = p.second;
minup(n, p.first.size());
rep(i, n - 1) r << p.first[i] << ' ';
r << p.first[n - 1];
return r;
}
template <typename T> ostream &operator<<(ostream &r, const pair<T *, int> p) {
int n = p.second - 1;
rep(i, n) r << p.first[i] << ' ';
return r << p.first[n];
}
template <typename T, size_t S>
ostream &operator<<(ostream &r, const T (&a)[S]) {
rep(i, S - 1) r << a[i] << ' ';
return r << a[S - 1];
}
double x, y;
vector<double> ix, iy;
double theta = 90.0;
Point res;
int main() {
iy.pb(theta * M_PI / 180.0);
while (~scanf("%lf,%lf", &x, &y) && x && y) {
theta -= y;
ix.pb(x);
iy.pb(theta * M_PI / 180.0);
}
rep(i, ix.size()) res += polar(ix[i], iy[i]);
printf("%d\n%d\n", static_cast<int>(res.real()),
static_cast<int>(res.imag()));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
#define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--)
#define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--)
#define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define vrep(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template <class T, class S> inline bool minup(T &m, S x) {
return m > (T)x ? (m = (T)x, true) : false;
}
template <class T, class S> inline bool maxup(T &m, S x) {
return m < (T)x ? (m = (T)x, true) : false;
}
const int INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;
struct Point : public complex<double> {
public:
Point() {
this->real(0);
this->imag(0);
}
Point(const double &x, const double &y) {
this->real(x);
this->imag(y);
}
Point(const complex<double> w) {
this->real(w.real());
this->imag(w.imag());
}
inline double dot(Point p) { return (conj(*this) * p).real(); } // ??????
inline double det(Point p) { return (conj(*this) * p).imag(); } // ??????
};
namespace std {
bool operator<(const Point &a, const Point &b) {
return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
} // namespace std
typedef vector<Point> Polygon;
#define currPoint(P, i) P[i]
#define nextPoint(P, i) P[(i + 1) % P.size()]
template <typename T> ostream &operator<<(ostream &r, const vector<T> t) {
vrep(v, t) r << *v << (v + 1 == t.end() ? "" : " ");
return r;
}
template <typename T>
ostream &operator<<(ostream &r, const pair<vector<T>, int> p) {
int n = p.second;
minup(n, p.first.size());
rep(i, n - 1) r << p.first[i] << ' ';
r << p.first[n - 1];
return r;
}
template <typename T> ostream &operator<<(ostream &r, const pair<T *, int> p) {
int n = p.second - 1;
rep(i, n) r << p.first[i] << ' ';
return r << p.first[n];
}
template <typename T, size_t S>
ostream &operator<<(ostream &r, const T (&a)[S]) {
rep(i, S - 1) r << a[i] << ' ';
return r << a[S - 1];
}
double x, y;
vector<double> ix, iy;
double theta = 90.0;
Point res;
int main() {
iy.pb(theta * M_PI / 180.0);
while (~scanf("%lf,%lf", &x, &y) && (x || y)) {
theta -= y;
ix.pb(x);
iy.pb(theta * M_PI / 180.0);
}
rep(i, ix.size()) res += polar(ix[i], iy[i]);
printf("%d\n%d\n", static_cast<int>(res.real()),
static_cast<int>(res.imag()));
return 0;
}
|
[["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 25]]
| 1
| 842
|
#include <math.h>
#include <stdio.h>
#define pi 3.14159265358979
int main() {
double teku[10000] = {0.0}, sita = pi / 2, set_sita[10000] = {0.0}, x = 0.0,
y = 0.0;
int i = 0;
while (scanf("%lf,%lf", &teku[i], &set_sita[i]) != EOF) {
if (teku[i] == 0 && set_sita[i] == 0)
break;
set_sita[i] = set_sita[i] / 180.0 * pi;
x += teku[i] * cos(sita);
y += teku[i] * sin(sita);
sita += set_sita[i];
i++;
}
if (x > 0)
x = floor(x);
else
x = ceil(x);
if (y > 0)
y = floor(y);
else
y = ceil(y);
printf("%.0f\n%.0f\n", floor(x), floor(y));
return 0;
}
|
#include <math.h>
#include <stdio.h>
#define pi 3.14159265358979
int main() {
double teku[10000] = {0.0}, sita = pi / 2, set_sita[10000] = {0.0}, x = 0.0,
y = 0.0;
int i = 0;
while (scanf("%lf,%lf", &teku[i], &set_sita[i]) != EOF) {
if (teku[i] == 0 && set_sita[i] == 0)
break;
set_sita[i] = set_sita[i] / 180.0 * pi;
x += teku[i] * cos(sita);
y += teku[i] * sin(sita);
sita -= set_sita[i];
i++;
}
if (x > 0)
x = floor(x);
else
x = ceil(x);
if (y > 0)
y = floor(y);
else
y = ceil(y);
printf("%.0f\n%.0f\n", floor(x), floor(y));
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 110]]
| 1
| 207
|
#include <iostream>
#include <math.h>
#include <stdio.h>
#define PI 3.141592
using namespace std;
int main() {
int a, b;
double x = 0, y = 0, dig = 0;
while (scanf("%d,%d", &a, &b)) {
if (a == 0 && b == 0)
break;
x += a * sin(dig * PI / 180.0);
y += a * cos(dig * PI / 180.0);
dig += b;
}
cout << (int)x << (int)y << endl;
return 0;
}
|
#include <iostream>
#include <math.h>
#include <stdio.h>
#define PI 3.141592
using namespace std;
int main() {
int a, b;
double x = 0, y = 0, dig = 0;
while (scanf("%d,%d", &a, &b)) {
if (a == 0 && b == 0)
break;
x += a * sin(dig * PI / 180.0);
y += a * cos(dig * PI / 180.0);
dig += b;
}
cout << (int)x << endl << (int)y << endl;
return 0;
}
|
[["+", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
| 1
| 113
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
double PI = 4 * atan(1);
int l, t1, t2 = 0, c = 0;
double x = 0, y = 0;
while (scanf("%d,%d", &l, &t1) && (l != 0 || t1 != 0)) {
x += (double)l * sin(PI * (double)t2 / 180);
y += (double)l * cos(PI * (double)t2 / 180);
t2 += t1;
}
cout << (int)x << " " << (int)y << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
double PI = 4 * atan(1);
int l, t1, t2 = 0, c = 0;
double x = 0, y = 0;
while (scanf("%d,%d", &l, &t1) && (l != 0 || t1 != 0)) {
x += (double)l * sin(PI * (double)t2 / 180);
y += (double)l * cos(PI * (double)t2 / 180);
t2 += t1;
}
cout << (int)x << endl;
cout << (int)y << endl;
}
|
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 31, 22]]
| 1
| 149
|
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
double x = 0, y = 0;
double m, d;
char c;
double next = 0;
while (cin >> m >> c >> d && m != 0 && d != 0) {
double rad = (90 - next) / 180.0 * M_PI;
x += m * cos(rad);
y += m * sin(rad);
next += d;
}
cout << (int)x << endl;
cout << (int)y << endl;
return 0;
}
|
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
double x = 0, y = 0;
double m, d;
char c;
double next = 0;
while (cin >> m >> c >> d && (m != 0 || d != 0)) {
double rad = (90 - next) / 180.0 * M_PI;
x += m * cos(rad);
y += m * sin(rad);
next += d;
}
cout << (int)x << endl;
cout << (int)y << endl;
return 0;
}
|
[["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 25]]
| 1
| 128
|
#include <cmath>
#include <cstdio>
#include <iostream>
constexpr auto PI = 3.14159265358979323846264338;
auto main() -> int {
int d, t;
double x = 0, y = 0;
int angle = 0;
while (std::scanf("%d,%d", &d, &t) == 2 && d && t) {
x += d * std::sin(angle * PI / 180.0);
y += d * std::cos(angle * PI / 180.0);
angle += t;
}
std::cout << static_cast<int>(x) << std::endl;
std::cout << static_cast<int>(y) << std::endl;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
constexpr auto PI = 3.14159265358979323846264338;
auto main() -> int {
int d, t;
double x = 0, y = 0;
int angle = 0;
while (std::scanf("%d,%d", &d, &t) == 2 && (d || t)) {
x += d * std::sin(angle * PI / 180.0);
y += d * std::cos(angle * PI / 180.0);
angle += t;
}
std::cout << static_cast<int>(x) << std::endl;
std::cout << static_cast<int>(y) << std::endl;
}
|
[["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 16, 12, 23, 0, 25]]
| 1
| 130
|
#include <iostream>
using namespace std;
int main() {
string s, t, u;
int n;
char ch;
cin >> n;
for (int loop = 0; loop < n; loop++) {
cin >> s >> t;
// cout << "\ns=" << s << endl << "t=" << t << endl;
if (s.length() > 80 || t.length() > 80) {
cout << "overflow" << endl;
continue;
}
while (s.length() > t.length())
t = "0" + t;
while (t.length() > s.length())
s = "0" + s;
/*
cout << "s=" << s << " len=" << s.length() << endl;
cout << "t=" << t << " len=" << t.length() << endl;
*/
u = "";
int c = 0;
for (int i = s.length(); i >= 0; --i) {
int a = s[i] - '0';
int b = t[i] - '0';
int sum = a + b + c;
if (sum >= 10) {
sum -= 10;
c = 1;
} else
c = 0;
ch = sum + '0';
u = ch + u;
}
if (c == 1)
u = "1" + u;
if (u.length() > 80)
cout << "overflow" << endl;
else
cout << u << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
string s, t, u;
int n;
char ch;
cin >> n;
for (int loop = 0; loop < n; loop++) {
cin >> s >> t;
// cout << "\ns=" << s << endl << "t=" << t << endl;
if (s.length() > 80 || t.length() > 80) {
cout << "overflow" << endl;
continue;
}
while (s.length() > t.length())
t = "0" + t;
while (t.length() > s.length())
s = "0" + s;
/*
cout << "s=" << s << " len=" << s.length() << endl;
cout << "t=" << t << " len=" << t.length() << endl;
*/
u = "";
int c = 0;
for (int i = s.length() - 1; i >= 0; --i) {
int a = s[i] - '0';
int b = t[i] - '0';
int sum = a + b + c;
if (sum >= 10) {
sum -= 10;
c = 1;
} else
c = 0;
ch = sum + '0';
u = ch + u;
}
if (c == 1)
u = "1" + u;
if (u.length() > 80)
cout << "overflow" << endl;
else
cout << u << endl;
}
return 0;
}
|
[["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
| 1
| 267
|
#include <cmath>
#include <iostream>
#include <sstream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int p1[100], p2[100];
for (int i = 0; i < 100; i++) {
p1[i] = 0;
p2[i] = 0;
}
string a, b;
cin >> a;
cin >> b;
if (a.size() > 80 || b.size() > 80) {
cout << "overflow" << endl;
continue;
}
int pos = 0;
for (unsigned i = a.size(); i > 0; i--) {
stringstream sst;
sst << a[i - 1];
sst >> p1[pos++];
}
pos = 0;
for (unsigned i = b.size(); i > 0; i--) {
stringstream sst;
sst << b[i - 1];
sst >> p2[pos++];
}
for (int i = 0; i < 100; i++) {
int ans = p1[i] + p2[i];
p1[i] = ans % 10;
p1[i + 1] += ans / 10;
}
bool flag = true;
for (int i = 99; i >= 0; i--) {
if (flag) {
if (p1[i] == 0)
continue;
else {
if (i > 80) {
cout << "overflow";
break;
}
flag = false;
}
}
cout << p1[i];
}
cout << endl;
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <sstream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int p1[100], p2[100];
for (int i = 0; i < 100; i++) {
p1[i] = 0;
p2[i] = 0;
}
string a, b;
cin >> a;
cin >> b;
if (a.size() > 80 || b.size() > 80) {
cout << "overflow" << endl;
continue;
}
int pos = 0;
for (unsigned i = a.size(); i > 0; i--) {
stringstream sst;
sst << a[i - 1];
sst >> p1[pos++];
}
pos = 0;
for (unsigned i = b.size(); i > 0; i--) {
stringstream sst;
sst << b[i - 1];
sst >> p2[pos++];
}
for (int i = 0; i < 100; i++) {
int ans = p1[i] + p2[i];
p1[i] = ans % 10;
p1[i + 1] += ans / 10;
}
bool flag = true;
for (int i = 99; i >= 0; i--) {
if (flag) {
if (i != 0 && p1[i] == 0)
continue;
else {
if (i > 79) {
cout << "overflow";
break;
}
flag = false;
}
}
cout << p1[i];
}
cout << endl;
}
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 336
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
using namespace std;
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
string a;
string b;
cin >> a;
cin >> b;
string res;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int carry = 0;
int idx;
for (int j = 0; j < min(a.size(), b.size()); j++) {
int lhs = a[j] - '0';
int rhs = b[j] - '0';
res.push_back((carry + lhs + rhs) % 10 + '0');
carry = (carry + lhs + rhs) / 10 ? 1 : 0;
idx = j;
}
for (int j = idx + 1; j < max(a.size(), b.size()); j++) {
if (a.size() > b.size()) {
int lhs = a[j] - '0';
res.push_back((carry + lhs) % 10 + '0');
carry = (carry + lhs) / 10 ? 1 : 0;
} else {
int rhs = b[j] - '0';
res.push_back((carry + rhs) % 10 + '0');
carry = (carry + rhs) / 10 ? 1 : 0;
}
}
if (carry)
res.push_back(carry + '0');
reverse(res.begin(), res.end());
res = (res.size() > 80) ? "over flow" : res;
cout << res << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
using namespace std;
int main() {
int t;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
string a;
string b;
cin >> a;
cin >> b;
string res;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int carry = 0;
int idx;
for (int j = 0; j < min(a.size(), b.size()); j++) {
int lhs = a[j] - '0';
int rhs = b[j] - '0';
res.push_back((carry + lhs + rhs) % 10 + '0');
carry = (carry + lhs + rhs) / 10 ? 1 : 0;
idx = j;
}
for (int j = idx + 1; j < max(a.size(), b.size()); j++) {
if (a.size() > b.size()) {
int lhs = a[j] - '0';
res.push_back((carry + lhs) % 10 + '0');
carry = (carry + lhs) / 10 ? 1 : 0;
} else {
int rhs = b[j] - '0';
res.push_back((carry + rhs) % 10 + '0');
carry = (carry + rhs) / 10 ? 1 : 0;
}
}
if (carry)
res.push_back(carry + '0');
reverse(res.begin(), res.end());
res = (res.size() > 80) ? "overflow" : res;
cout << res << endl;
}
}
|
[["-", 0, 1, 0, 11, 12, 41, 64, 5, 0, 6], ["+", 0, 1, 0, 11, 12, 41, 64, 5, 0, 6]]
| 1
| 388
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a, b, ans;
cin >> a >> b;
int as = a.size(), bs = b.size(), ms = (as > bs) ? as : bs, t = 0;
for (int i = 0; i < ms; i++) {
if (i < as && i < bs) {
t = a[as - i - 1] + b[bs - i - 1] + t / 10 - 2 * '0';
} else if (i < as) {
t = a[as - i - 1] + t / 10 - '0';
} else if (i < bs) {
t = b[bs - i - 1] + t / 10 - '0';
}
ans += (char)(t % 10) + '0';
}
if (t / 10) {
ans += '1';
}
if (ans.size() >= 80) {
cout << "over flow" << endl;
} else {
for (int i = 0; i < ans.size(); i++) {
cout << ans[ans.size() - i - 1];
}
cout << endl;
}
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string a, b, ans;
cin >> a >> b;
int as = a.size(), bs = b.size(), ms = (as > bs) ? as : bs, t = 0;
for (int i = 0; i < ms; i++) {
if (i < as && i < bs) {
t = a[as - i - 1] + b[bs - i - 1] + t / 10 - 2 * '0';
} else if (i < as) {
t = a[as - i - 1] + t / 10 - '0';
} else if (i < bs) {
t = b[bs - i - 1] + t / 10 - '0';
}
ans += (char)(t % 10) + '0';
}
if (t / 10) {
ans += '1';
}
if (ans.size() > 80) {
cout << "overflow" << endl;
} else {
for (int i = 0; i < ans.size(); i++) {
cout << ans[ans.size() - i - 1];
}
cout << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 282
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int i, j, n, f;
string s1, s2;
cin >> n;
while (n--) {
cin >> s1 >> s2;
f = 0;
if (s1.size() < s2.size())
swap(s1, s2);
for (i = 0; i < s2.size(); i++) {
s1[i + s1.size() - s2.size()] += s2[i] - '0';
}
for (i = s1.size() - 1; i > 0; i--) {
if (s1[i] > '9') {
s1[i] -= 10;
s1[i - 1]++;
}
}
if (s1[0] > '9') {
s1[0] -= 10;
f++;
}
if (s1.size() + f < 80) {
if (f)
cout << "1";
cout << s1;
} else
cout << "overflow";
cout << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int i, j, n, f;
string s1, s2;
cin >> n;
while (n--) {
cin >> s1 >> s2;
f = 0;
if (s1.size() < s2.size())
swap(s1, s2);
for (i = 0; i < s2.size(); i++) {
s1[i + s1.size() - s2.size()] += s2[i] - '0';
}
for (i = s1.size() - 1; i > 0; i--) {
if (s1[i] > '9') {
s1[i] -= 10;
s1[i - 1]++;
}
}
if (s1[0] > '9') {
s1[0] -= 10;
f++;
}
if (s1.size() + f <= 80) {
if (f)
cout << "1";
cout << s1;
} else
cout << "overflow";
cout << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 241
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> P;
int main() {
int t;
cin >> t;
while (t--) {
string s, t;
cin >> s >> t;
int len = (int)max(s.size(), t.size());
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
string ans;
bool f = false;
for (int i = 0; i < len; i++) {
char add = 0;
if (f) {
add++;
f = false;
}
add += (i < (int)s.size()) ? s[i] - '0' : 0;
add += (i < (int)t.size()) ? t[i] - '0' : 0;
if (add >= 10) {
add -= 10;
f = true;
}
ans.push_back(add + '0');
}
if (f)
ans.push_back('1');
reverse(ans.begin(), ans.end());
if (ans.length() >= 80) {
cout << "overflow" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> P;
int main() {
int t;
cin >> t;
while (t--) {
string s, t;
cin >> s >> t;
int len = (int)max(s.size(), t.size());
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
string ans;
bool f = false;
for (int i = 0; i < len; i++) {
char add = 0;
if (f) {
add++;
f = false;
}
add += (i < (int)s.size()) ? s[i] - '0' : 0;
add += (i < (int)t.size()) ? t[i] - '0' : 0;
if (add >= 10) {
add -= 10;
f = true;
}
ans.push_back(add + '0');
}
if (f)
ans.push_back('1');
reverse(ans.begin(), ans.end());
if (ans.length() > 80) {
cout << "overflow" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 296
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string a, b;
vector<int> sum;
int al, bl, sl;
int n, up, num;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a >> b;
al = a.size() - 1;
bl = b.size() - 1;
up = 0;
while (al >= 0 || bl >= 0) {
num = up;
if (al >= 0)
num += a[al] - 48;
if (bl >= 0)
num += b[bl] - 48;
if (num > 9) {
sum.push_back(num - 10);
up = 1;
} else {
sum.push_back(num);
up = 0;
}
al -= 1;
bl -= 1;
}
if (up == 1) {
sum.push_back(1);
}
sl = sum.size();
if (sl >= 80) {
cout << "overflow" << endl;
} else {
for (int j = sl - 1; j >= 0; --j) {
cout << sum[j];
}
cout << endl;
sum.clear();
}
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string a, b;
vector<int> sum;
int al, bl, sl;
int n, up, num;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a >> b;
al = a.size() - 1;
bl = b.size() - 1;
up = 0;
while (al >= 0 || bl >= 0) {
num = up;
if (al >= 0)
num += a[al] - 48;
if (bl >= 0)
num += b[bl] - 48;
if (num > 9) {
sum.push_back(num - 10);
up = 1;
} else {
sum.push_back(num);
up = 0;
}
al -= 1;
bl -= 1;
}
if (up == 1) {
sum.push_back(1);
}
sl = sum.size();
if (sl > 80) {
cout << "overflow" << endl;
} else {
for (int j = sl - 1; j >= 0; --j) {
cout << sum[j];
}
cout << endl;
}
sum.clear();
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 260
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)
int main() {
string a, b;
vector<int> m, n, s;
int set;
m.resize(81, 0);
n.resize(81, 0);
s.resize(81, 0);
cin >> set;
while (set-- > 0) {
cin >> a >> b;
for (int i = 0; i < 81; i++) {
m[i] = n[i] = s[i] = 0;
}
if (a.size() > 80 || b.size() > 80) {
cout << "overflow" << endl;
} else {
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = 0; i < a.size(); i++) {
m[i] = a[i] - '0';
}
for (int i = 0; i < b.size(); i++) {
n[i] = b[i] - '0';
}
for (int i = 0; i < 80; i++) {
s[i] += m[i] + n[i];
if (s[i] >= 10) {
s[i + 1]++;
s[i] -= 10;
}
}
int digit = 81;
while (--digit > 0) {
if (s[digit] != 0) {
break;
}
}
if (digit >= 79) {
cout << "overflow" << endl;
} else {
for (int i = digit; i >= 0; i--) {
cout << s[i];
}
cout << endl;
}
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)
int main() {
string a, b;
vector<int> m, n, s;
int set;
m.resize(81, 0);
n.resize(81, 0);
s.resize(81, 0);
cin >> set;
while (set-- > 0) {
cin >> a >> b;
for (int i = 0; i < 81; i++) {
m[i] = n[i] = s[i] = 0;
}
if (a.size() > 80 || b.size() > 80) {
cout << "overflow" << endl;
} else {
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for (int i = 0; i < a.size(); i++) {
m[i] = a[i] - '0';
}
for (int i = 0; i < b.size(); i++) {
n[i] = b[i] - '0';
}
for (int i = 0; i < 80; i++) {
s[i] += m[i] + n[i];
if (s[i] >= 10) {
s[i + 1]++;
s[i] -= 10;
}
}
int digit = 81;
while (--digit > 0) {
if (s[digit] != 0) {
break;
}
}
if (digit >= 80) {
cout << "overflow" << endl;
} else {
for (int i = digit; i >= 0; i--) {
cout << s[i];
}
cout << endl;
}
}
}
return 0;
}
|
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
| 1
| 399
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define MOJI 48
using namespace std;
int multiple(string a, string b);
char c[111111];
int main() {
int n;
string a, b;
while (cin >> n) {
for (int i = 0; i < n; i++) {
cin >> a;
cin >> b;
int k = multiple(a, b);
if (k >= 80) {
cout << "overflow" << endl;
} else {
for (int i = k - 1; i >= 0; i--) {
printf("%d", c[i]);
}
cout << endl;
}
}
}
}
int multiple(string a, string b) {
int a_size, b_size, w = 0;
char k = 0; // 桁上げ
a_size = a.size();
b_size = b.size();
while (a_size > 0 || b_size > 0 || k == 1) {
if (a_size > 0 && b_size > 0) {
c[w] = (a[a_size - 1] - MOJI + b[b_size - 1] - MOJI + k) % 10;
k = (k + (a[a_size - 1] - MOJI) + (b[b_size - 1] - MOJI)) / 10;
} else if (a_size > 0 && b_size <= 0) {
c[w] = ((a[a_size - 1] - MOJI) + k) % 10;
k = (a[a_size - 1] - MOJI + k) / 10;
} else if (a_size <= 0 && b_size > 0) {
c[w] = (b[b_size - 1] - MOJI + k) % 10;
k = (k + b[b_size - 1] - MOJI) / 10;
} else {
c[w] = k;
k = 0;
}
a_size--;
b_size--;
w++;
}
return w;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define MOJI 48
using namespace std;
int multiple(string a, string b);
char c[111111];
int main() {
int n;
string a, b;
while (cin >> n) {
for (int i = 0; i < n; i++) {
cin >> a;
cin >> b;
int k = multiple(a, b);
if (k > 80) {
cout << "overflow" << endl;
} else {
for (int i = k - 1; i >= 0; i--) {
printf("%d", c[i]);
}
cout << endl;
}
}
}
}
int multiple(string a, string b) {
int a_size, b_size, w = 0;
char k = 0; // 桁上げ
a_size = a.size();
b_size = b.size();
while (a_size > 0 || b_size > 0 || k == 1) {
if (a_size > 0 && b_size > 0) {
c[w] = (a[a_size - 1] - MOJI + b[b_size - 1] - MOJI + k) % 10;
k = (k + (a[a_size - 1] - MOJI) + (b[b_size - 1] - MOJI)) / 10;
} else if (a_size > 0 && b_size <= 0) {
c[w] = ((a[a_size - 1] - MOJI) + k) % 10;
k = (a[a_size - 1] - MOJI + k) / 10;
} else if (a_size <= 0 && b_size > 0) {
c[w] = (b[b_size - 1] - MOJI + k) % 10;
k = (k + b[b_size - 1] - MOJI) / 10;
} else {
c[w] = k;
k = 0;
}
a_size--;
b_size--;
w++;
}
return w;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 399
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring> //strlen
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
bool solve() {
char str1[10000], str2[10000];
scanf("%s %s", str1, str2);
int n1 = strlen(str1);
int n2 = strlen(str2);
int n = max(n1, n2);
char str[10000];
int c = 0;
int i = 0;
while (i < n) {
int a = c;
if (i < n1) {
a += (str1[n1 - i - 1] - '0');
}
if (i < n2) {
a += (str2[n2 - i - 1] - '0');
}
c = a / 10;
a = a % 10;
str[i] = a + '0';
i++;
}
if (c) {
str[i] = c + '0';
i++;
}
if (i > 81) {
cout << "overflow" << endl;
return true;
}
for (int j = i - 1; j >= 0; j--) {
cout << str[j];
}
cout << endl;
return true;
}
int main() {
cout.setf(ios::fixed);
cout.precision(5);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
solve();
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring> //strlen
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
bool solve() {
// なぜかわからないがstirngだと数字が大きいとSegmentation fault
/*
string str1,str2;
cin>> str1>> str2;
int n1 = str1.size();
int n2 = str2.size();
*/
char str1[10000], str2[10000];
scanf("%s %s", str1, str2);
int n1 = strlen(str1);
int n2 = strlen(str2);
int n = max(n1, n2);
/* string str="";
*/
char str[10000];
int c = 0;
int i = 0;
while (i < n) {
int a = c;
if (i < n1) {
a += (str1[n1 - i - 1] - '0');
}
if (i < n2) {
a += (str2[n2 - i - 1] - '0');
}
c = a / 10;
a = a % 10;
str[i] = a + '0';
i++;
}
if (c) {
str[i] = c + '0';
i++;
}
if (i >= 81) {
cout << "overflow" << endl;
return true;
}
for (int j = i - 1; j >= 0; j--) {
cout << str[j];
}
cout << endl;
return true;
}
int main() {
cout.setf(ios::fixed);
cout.precision(5);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
solve();
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 307
|
#include <stdio.h>
#include <string.h>
int main() {
int n, ans[100], kuri, i, j, ap, bp;
char a[1000], b[1000];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s%s", a, b);
if (strlen(a) > 80 || strlen(b) > 80) {
printf("overflow\n");
continue;
}
ap = strlen(a) - 1;
bp = strlen(b) - 1;
j = 0;
kuri = 0;
while (ap >= 0 || bp >= 0) {
ans[j] = kuri;
if (ap >= 0)
ans[j] += a[ap] - '0';
if (bp >= 0)
ans[j] += b[bp] - '0';
kuri = ans[j] / 10;
ans[j] % 10;
j++;
ap--;
bp--;
}
if (kuri == 1)
ans[j] = 1;
else
j--;
if (j >= 80) {
printf("overflow\n");
continue;
}
for (; j >= 0; j--) {
printf("%d", ans[j]);
}
printf("\n");
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int main() {
int n, ans[100], kuri, i, j, ap, bp;
char a[1000], b[1000];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s%s", a, b);
if (strlen(a) > 80 || strlen(b) > 80) {
printf("overflow\n");
continue;
}
ap = strlen(a) - 1;
bp = strlen(b) - 1;
j = 0;
kuri = 0;
while (ap >= 0 || bp >= 0) {
ans[j] = kuri;
if (ap >= 0)
ans[j] += a[ap] - '0';
if (bp >= 0)
ans[j] += b[bp] - '0';
kuri = ans[j] / 10;
ans[j] %= 10;
j++;
ap--;
bp--;
}
if (kuri == 1)
ans[j] = 1;
else
j--;
if (j >= 80) {
printf("overflow\n");
continue;
}
for (; j >= 0; j--) {
printf("%d", ans[j]);
}
printf("\n");
}
return 0;
}
|
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 109], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 132]]
| 1
| 282
|
#include <cstdio>
#include <cstring>
#define MAX_NUM 100
using namespace std;
void array_add(int *a, int *b) {
int i;
for (i = MAX_NUM - 1; i > 0; i--) {
a[i] = a[i] + b[i];
a[i - 1] = a[i - 1] + a[i] / 10;
a[i] %= 10;
}
}
int main(void) {
int n, i, j, len1, len2, val1[MAX_NUM], val2[MAX_NUM];
char c;
scanf("%d%*c", &n);
for (i = 0; i < n; i++) {
for (j = 0; (c = getchar()) != '\n'; j++) {
val1[j] = c - '0';
}
len1 = j;
for (j = 0; (c = getchar()) != '\n'; j++) {
val2[j] = c - '0';
}
len2 = j;
for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len1; j--) {
val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
}
for (; j >= 0; j--) {
val1[j] = 0;
}
val1[MAX_NUM] = 0;
for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len2; j--) {
val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
}
for (; j >= 0; j--) {
val2[j] = 0;
}
array_add(val1, val2);
for (j = 0; val1[j] == 0 && j < MAX_NUM; j++)
;
if (j <= MAX_NUM - 81)
printf("overflow");
else if (j == MAX_NUM)
printf("0");
else {
for (; j < MAX_NUM; j++) {
printf("%d", val1[j]);
}
}
printf("\n");
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#define MAX_NUM 32767
using namespace std;
void array_add(int *a, int *b) {
int i;
for (i = MAX_NUM - 1; i > 0; i--) {
a[i] = a[i] + b[i];
a[i - 1] = a[i - 1] + a[i] / 10;
a[i] %= 10;
}
}
int main(void) {
int n, i, j, len1, len2, val1[MAX_NUM], val2[MAX_NUM];
char c;
scanf("%d%*c", &n);
for (i = 0; i < n; i++) {
for (j = 0; (c = getchar()) != '\n'; j++) {
val1[j] = c - '0';
}
len1 = j;
for (j = 0; (c = getchar()) != '\n'; j++) {
val2[j] = c - '0';
}
len2 = j;
for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len1; j--) {
val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
}
for (; j >= 0; j--) {
val1[j] = 0;
}
val1[MAX_NUM] = 0;
for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len2; j--) {
val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
}
for (; j >= 0; j--) {
val2[j] = 0;
}
array_add(val1, val2);
for (j = 0; val1[j] == 0 && j < MAX_NUM; j++)
;
if (j <= MAX_NUM - 81)
printf("overflow");
else if (j == MAX_NUM)
printf("0");
else {
for (; j < MAX_NUM; j++) {
printf("%d", val1[j]);
}
}
printf("\n");
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
| 1
| 444
|
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
string a;
string b;
int kari;
cin >> kari;
for (int o = 0; o < kari; o++) {
int c[80] = {0};
int d[80] = {0};
int e[81] = {0};
int counter;
cin >> a;
cin >> b;
if (a.size() > 80 || b.size() > 80) {
cout << "overflow" << endl;
} else {
for (int i = a.size() - 1; i >= 0; i--) {
c[a.size() - 1 - i] = a[i] - '0';
}
for (int i = b.size() - 1; i >= 0; i--) {
d[b.size() - 1 - i] = b[i] - '0';
}
for (int j = 0; j < 80; j++) {
e[j] += c[j] + d[j];
if (e[j] >= 10) {
e[j + 1] = e[j] / 10;
e[j] = e[j] % 10;
}
}
}
if (e[80] > 0) {
cout << "overflow" << endl;
} else {
for (int k = 79; k >= 0; k--) {
if (e[k] != 0) {
counter = k;
break;
}
}
for (int k = counter; k >= 0; k--) {
cout << e[k];
}
cout << endl;
}
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
string a;
string b;
int kari;
cin >> kari;
for (int o = 0; o < kari; o++) {
int c[80] = {0};
int d[80] = {0};
int e[81] = {0};
int counter = 0;
cin >> a;
cin >> b;
if (a.size() > 80 || b.size() > 80) {
cout << "overflow" << endl;
continue;
} else {
for (int i = a.size() - 1; i >= 0; i--) {
c[a.size() - 1 - i] = a[i] - '0';
}
for (int i = b.size() - 1; i >= 0; i--) {
d[b.size() - 1 - i] = b[i] - '0';
}
for (int j = 0; j < 80; j++) {
e[j] += c[j] + d[j];
if (e[j] >= 10) {
e[j + 1] = e[j] / 10;
e[j] = e[j] % 10;
}
}
}
if (e[80] > 0) {
cout << "overflow" << endl;
} else {
for (int k = 79; k >= 0; k--) {
if (e[k] != 0) {
counter = k;
break;
}
}
for (int k = counter; k >= 0; k--) {
cout << e[k];
}
cout << endl;
}
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 116, 0, 117]]
| 1
| 358
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
char calc(char x, char y, char z, bool &C) {
int a = x - '0', b = y - '0', c = z - '0';
int d = a + b + c;
if (d >= 10) {
C = true;
d -= 10;
}
return d + '0';
}
string sum(string a, string b) {
string res = "";
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int length;
if ((int)a.size() > (int)b.size()) {
length = (int)a.size();
for (int i = (int)b.size(); i < length; i++) {
b += '0';
}
} else {
length = (int)b.size();
for (int i = (int)a.size(); i < length; i++) {
a += '0';
}
}
for (int i = 0; i <= length; i++)
res += '0';
for (int i = 0; i < length; i++) {
bool C = false;
res[i] = calc(a[i], b[i], res[i], C);
if (C)
res[i + 1] = ((res[i + 1] - '0') + 1) + '0';
}
for (int i = length;; i--) {
if (res[i] == '0') {
res.erase(res.begin() + i);
} else {
break;
}
}
reverse(res.begin(), res.end());
return res;
}
int main() {
int n;
cin >> n;
while (n--) {
string a, b;
cin >> a >> b;
string c = sum(a, b);
if ((int)c.size() >= 80)
cout << "overflow" << endl;
else
cout << c << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
char calc(char x, char y, char z, bool &C) {
int a = x - '0', b = y - '0', c = z - '0';
int d = a + b + c;
if (d >= 10) {
C = true;
d -= 10;
}
return d + '0';
}
string sum(string a, string b) {
string res = "";
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int length;
if ((int)a.size() > (int)b.size()) {
length = (int)a.size();
for (int i = (int)b.size(); i < length; i++) {
b += '0';
}
} else {
length = (int)b.size();
for (int i = (int)a.size(); i < length; i++) {
a += '0';
}
}
for (int i = 0; i <= length; i++)
res += '0';
for (int i = 0; i < length; i++) {
bool C = false;
res[i] = calc(a[i], b[i], res[i], C);
if (C)
res[i + 1] = ((res[i + 1] - '0') + 1) + '0';
}
for (int i = length; i > 0; i--) {
if (res[i] == '0') {
res.erase(res.begin() + i);
} else {
break;
}
}
reverse(res.begin(), res.end());
return res;
}
int main() {
int n;
cin >> n;
while (n--) {
string a, b;
cin >> a >> b;
string c = sum(a, b);
if ((int)c.size() > 80)
cout << "overflow" << endl;
else
cout << c << endl;
}
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 472
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
while (n-- > 0) {
string num1, num2;
cin >> num1 >> num2;
if (num1.size() > 80 || num2.size() > 80) {
cout << "overflow" << endl;
continue;
}
int sum[101];
int degit = 0;
for (int i = 0; i < 101; i++)
sum[i] = 0;
for (int i = 0; i < num1.size(); i++) {
sum[100 - i] = num1[num1.size() - i - 1] - '0';
}
int d;
for (int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++) {
int now;
if (i < num2.size()) {
now =
sum[100 - i] + (int)num2[num2.size() - i - 1] - (int)('0') + degit;
} else {
now = sum[100 - i] + degit;
}
sum[100 - i] = (now % 10);
if (now >= 10)
degit = 1;
else
degit = 0;
d = i;
}
if (d <= 80) {
for (int i = 100 - d; i < 101; i++)
cout << sum[i];
cout << endl;
} else {
cout << "overflow" << endl;
}
}
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
while (n-- > 0) {
string num1, num2;
cin >> num1 >> num2;
if (num1.size() > 80 || num2.size() > 80) {
cout << "overflow" << endl;
continue;
}
int sum[101];
int degit = 0;
for (int i = 0; i < 101; i++)
sum[i] = 0;
for (int i = 0; i < num1.size(); i++) {
sum[100 - i] = num1[num1.size() - i - 1] - '0';
}
int d;
for (int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++) {
int now;
if (i < num2.size()) {
now =
sum[100 - i] + (int)num2[num2.size() - i - 1] - (int)('0') + degit;
} else {
now = sum[100 - i] + degit;
}
sum[100 - i] = (now % 10);
if (now >= 10)
degit = 1;
else
degit = 0;
d = i;
}
if (d < 80) {
for (int i = 100 - d; i < 101; i++)
cout << sum[i];
cout << endl;
} else {
cout << "overflow" << endl;
}
}
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 329
|
#include <algorithm>
#include <iostream>
#include <string>
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::string str, str2, res;
std::cin >> str >> str2;
std::reverse(str.begin(), str.end());
std::reverse(str2.begin(), str2.end());
bool up = 0;
for (int i = 0; up || i < std::max(str.size(), str2.size()); i++) {
int a = 0, b = 0;
if (str.size() > i)
a = str[i] - '0';
if (str2.size() > i)
b = str2[i] - '0';
if (up + a + b >= 10) {
res += (up + a + b - 10 + '0');
up = 1;
} else {
res += (up + a + b + '0');
up = 0;
}
}
std::reverse(res.begin(), res.end());
if (res.size() >= 80)
std::cout << "overflow" << std::endl;
else
std::cout << res << std::endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::string str, str2, res;
std::cin >> str >> str2;
std::reverse(str.begin(), str.end());
std::reverse(str2.begin(), str2.end());
bool up = 0;
for (int i = 0; up || i < std::max(str.size(), str2.size()); i++) {
int a = 0, b = 0;
if (str.size() > i)
a = str[i] - '0';
if (str2.size() > i)
b = str2[i] - '0';
if (up + a + b >= 10) {
res += (up + a + b - 10 + '0');
up = 1;
} else {
res += (up + a + b + '0');
up = 0;
}
}
std::reverse(res.begin(), res.end());
if (res.size() > 80)
std::cout << "overflow" << std::endl;
else
std::cout << res << std::endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
| 1
| 283
|
n = gets.to_i
n.times do
a = gets.to_i
b = gets.to_i
if (10 ** 81) < (a + b)
puts "overflow"
else
puts (a + b)
end
end
|
n = gets.to_i
n.times do
a = gets.to_i
b = gets.to_i
if (10 ** 80) <= (a + b)
puts "overflow"
else
puts (a + b)
end
end
|
[["-", 0, 121, 15, 738, 31, 739, 0, 738, 12, 612], ["+", 0, 121, 15, 738, 31, 739, 0, 738, 12, 612], ["-", 196, 737, 8, 736, 0, 121, 15, 738, 17, 18], ["+", 196, 737, 8, 736, 0, 121, 15, 738, 17, 19]]
| 4
| 44
|
n = gets.to_i
n.times do
a = gets.to_i
b = gets.to_i
c = a + b
c = c.to_s
if c.length >= 80
puts 'overflow'
else
puts c
end
end
|
n = gets.to_i
n.times do
a = gets.to_i
b = gets.to_i
c = a + b
c = c.to_s
if c.length > 80
puts 'overflow'
else
puts c
end
end
|
[["-", 196, 737, 8, 736, 0, 121, 15, 738, 17, 20], ["+", 196, 737, 8, 736, 0, 121, 15, 738, 17, 47]]
| 4
| 44
|
gets.to_i.times do
a = gets.chomp.split(//).reverse
b = gets.chomp.split(//).reverse
if (a.length > 80) || (b.length > 80)
p 'overflow'
else
a.push(*Array.new(80 - a.length, 0))
b.push(*Array.new(80 - b.length, 0))
result = []
temp = 0
80.times do |i|
result.unshift((a[i].to_i + b[i].to_i + temp) % 10)
temp = ((a[i].to_i + b[i].to_i + temp) / 10)
end
if temp.zero?
p result.join.to_i
else
p 'overflow'
end
end
end
|
gets.to_i.times do
a = gets.chomp.split(//).reverse
b = gets.chomp.split(//).reverse
if (a.length > 80) || (b.length > 80)
puts 'overflow'
else
a.push(*Array.new(80 - a.length, 0))
b.push(*Array.new(80 - b.length, 0))
result = []
temp = 0
80.times do |i|
result.unshift((a[i].to_i + b[i].to_i + temp) % 10)
temp = ((a[i].to_i + b[i].to_i + temp) / 10)
end
if temp.zero?
puts result.join.to_i
else
puts 'overflow'
end
end
end
|
[["-", 8, 736, 0, 121, 64, 749, 0, 652, 735, 22], ["+", 8, 736, 0, 121, 64, 749, 0, 652, 735, 22], ["-", 75, 95, 0, 121, 64, 749, 0, 652, 735, 22], ["+", 75, 95, 0, 121, 64, 749, 0, 652, 735, 22], ["-", 75, 95, 0, 121, 75, 95, 0, 652, 735, 22], ["+", 75, 95, 0, 121, 75, 95, 0, 652, 735, 22]]
| 4
| 169
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.