結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
nanasili
|
| 提出日時 | 2014-11-28 02:19:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 4,059 bytes |
| コンパイル時間 | 1,467 ms |
| コンパイル使用メモリ | 94,908 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-15 00:28:41 |
| 合計ジャッジ時間 | 2,398 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:181:27: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
181 | for (int i = 0; i < 49-r; i++) cout << "0";
| ~~^~
main.cpp:170:3: warning: ‘l’ may be used uninitialized in this function [-Wmaybe-uninitialized]
170 | if (l == 50) {
| ^~
main.cpp:141:7: warning: ‘p’ may be used uninitialized in this function [-Wmaybe-uninitialized]
141 | if (i <= p) {
| ^~
ソースコード
#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];
a[i][j] = a[i][j] != 0 ? a[i][j] : '0';
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];
b[i][j] = b[i][j] != 0 ? b[i][j] : '0';
bbb[j] = (bbb[j]+(b[i][j]-'0')+c)%10;
c = (t+(b[i][j]-'0')+c)/10;
}
}
// 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;
}
}
int p;
for (int i = 0; i < 99; i++) {
if (ans[i] > 0) {
p = i;
break;
}
}
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