結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
nanasili
|
| 提出日時 | 2014-11-28 02:09:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,954 bytes |
| コンパイル時間 | 1,318 ms |
| コンパイル使用メモリ | 99,160 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-03 10:03:02 |
| 合計ジャッジ時間 | 6,013 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 WA * 7 OLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:136:7: warning: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
136 | if (i <= p) {
| ^~
main.cpp:104:7: note: ‘p’ was declared here
104 | int p;
| ^
main.cpp:165:3: warning: ‘l’ may be used uninitialized [-Wmaybe-uninitialized]
165 | if (l == 50) {
| ^~
main.cpp:150:7: note: ‘l’ was declared here
150 | int l, r;
| ^
main.cpp:168:21: warning: ‘r’ may be used uninitialized [-Wmaybe-uninitialized]
168 | for (int i = l; i <= r; i++) {
| ~~^~~~
main.cpp:150:10: note: ‘r’ was declared here
150 | int l, r;
| ^
ソースコード
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;
bool compare(const long double a, const long double b) {
return fabsl(a) < fabsl(b);
}
int main() {
int n;
cin >> n;
vector<string> a, b;
int ans[100] = {0}, bbb[100] = {0};
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == '-') {
b.push_back(s.substr(1));
}else {
a.push_back(s);
}
}
for (int i = 0; i < a.size(); i++) {
bool ok = false;
for (int j = 0; j < a[i].size(); j++) {
if (a[i][j] == '.') {
ok = true;
string t = "";
for (int k = 0; k < 50-j; k++) t += "0";
a[i] = t+a[i].substr(0, j)+a[i].substr(j+1);
int n = a[i].size();
for (int k = 0; k < 100-n; k++) a[i] += "0";
}
}
if (!ok) {
int n = a[i].size();
string t = "";
for (int j = 0; j < 50-n; j++) t += "0";
a[i] = t+a[i];
n = a.size();
for (int j = 0; j < 100-n; j++) a[i] += "0";
}
}
for (int i = 0; i < b.size(); i++) {
bool ok = false;
for (int j = 0; j < b[i].size(); j++) {
if (b[i][j] == '.') {
ok = true;
string t = "";
for (int k = 0; k < 50-j; k++) t += "0";
b[i] = t+b[i].substr(0, j)+b[i].substr(j+1);
int n = b[i].size();
for (int k = 0; k < 100-n; k++) b[i] += "0";
}
}
if (!ok) {
int n = b[i].size();
string t = "";
for (int j = 0; j < 50-n; j++) t += "0";
b[i] = t+b[i];
n = b.size();
for (int j = 0; j < 100-n; j++) b[i] += "0";
}
}
int c = 0;
for (int i = 0; i < a.size(); i++) {
c = 0;
for (int j = 99; j >= 0; j--) {
int t = ans[j];
ans[j] = (ans[j]+(a[i][j]-'0')+c)%10;
c = (t+(a[i][j]-'0')+c)/10;
}
}
for (int i = 0; i < b.size(); i++) {
c = 0;
for (int j = 99; j >= 0; j--) {
int t = bbb[j];
bbb[j] = (bbb[j]+(b[i][j]-'0')+c)%10;
c = (t+(b[i][j]-'0')+c)/10;
}
}
int p;
for (int i = 0; i < 99; i++) {
if (ans[i] > 0) {
p = i;
break;
}
}
// for (int i = 0; i < 100; i++) cout << ans[i];
// cout << endl;
// for (int i = 0; i < 100; i++) cout << bbb[i];
// cout << endl;
bool ok = false;
for (int i = 0; i < 100; i++) {
if (ans[i] < bbb[i]) {
ok = true;
}else if (ans[i] > bbb[i]) {
break;
}
}
if (ok) {
for (int i = 0; i < 100; i++) {
int t = ans[i];
ans[i] = bbb[i];
bbb[i] = t;
}
}
bool minus = false;
c = false;
for (int i = 99; i >= 0; i--) {
if (ans[i]-bbb[i]-c < 0) {
if (i <= p) {
minus = true;
ans[i] = bbb[i]-(ans[i]-c);
c = false;
}else {
ans[i] = 10-(bbb[i]-(ans[i]-c));
c = true;
}
}else {
ans[i] = ans[i]-bbb[i]-c;
c = false;
}
}
int l, r;
for (int i = 0; i < 100; i++) {
if (ans[i] > 0) {
l = i;
break;
}
}
for (int i = 100; i >= 0; i--) {
if (ans[i] > 0) {
r = i;
break;
}
}
if (!(minus && ok) && (minus || ok)) cout << "-";
if (l == 50) {
cout << "0";
}
for (int i = l; i <= r; i++) {
if (i == 50) {
cout << "." << ans[i];
}else {
cout << ans[i];
}
}
if (r < 50) {
for (int i = 0; i < 49-r; i++) cout << "0";
cout << ".";
for (int i = 0; i < 10; i++) cout << "0";
}else {
for (int i = 0; i < 10-((r+1)-50); i++) cout << "0";
}
cout << endl;
}
nanasili