結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
ふっぴー
|
| 提出日時 | 2018-01-04 00:22:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,318 bytes |
| コンパイル時間 | 1,969 ms |
| コンパイル使用メモリ | 177,948 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-23 02:35:27 |
| 合計ジャッジ時間 | 2,889 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 16 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
int main() {
int n, i, j;
cin >> n;
vs sei, fu;
for (i = 0; i < n; i++) {
string s;
cin >> s;
if (s[0] == '-') {
fu.push_back(s);
}
else {
sei.push_back(s);
}
}
vi sumsei(31); //sum[30]が小数第10位、sum[20]が1の位、sum[19]が10の位
for (i = 0; i < sei.size(); i++) {
string b = "?";
for (j = 0; j < sei[i].size(); j++) {
if (sei[i][j] == '.') {
b = sei[i].substr(j + 1, sei[i].size() - j - 1);
sei[i] = sei[i].substr(0, j);
}
}
for (j = sei[i].size() - 1; j >= 0; j--) {
sumsei[21 - sei[i].size() + j] += sei[i][j] - '0';
}
if (b != "?") {
for (j = 0; j < b.size(); j++) {
sumsei[21 + j] += b[j] - '0';
}
}
}
vi sumfu(31);
for (i = 0; i < fu.size(); i++) {
string b = "?";
fu[i].erase(fu[i].begin());
for (j = 0; j < fu[i].size(); j++) {
if (fu[i][j] == '.') {
b = fu[i].substr(j + 1, fu[i].size() - j - 1);
fu[i] = fu[i].substr(0, j);
}
}
for (j = fu[i].size() - 1; j >= 0; j--) {
sumfu[21 - fu[i].size() + j] += fu[i][j] - '0';
}
if (b != "?") {
for (j = 0; j < b.size(); j++) {
sumfu[21 + j] += b[j] - '0';
}
}
}
//DEBUG_VEC(sumsei);
//DEBUG_VEC(sumfu);
for (i = 0; i < 31; i++) {
sumsei[i] -= sumfu[i];
}
vi sumsei2 = sumsei;
bool flag = true;
for (i = 30; i >= 1; i--) {
if (sumsei[i] < 0) {
int cnt = sumsei[i] / 10 + 1;
sumsei[i - 1] -= cnt;
sumsei[i] += 10 * cnt;
}
else if (sumsei[i] >= 10) {
int cnt = sumsei[i] / 10;
sumsei[i] -= cnt * 10;
sumsei[i - 1] += cnt;
}
}
if (sumsei[0] < 0) {
flag = false;
for (i = 0; i < 31; i++) {
sumsei2[i] *= -1;
}
for (i = 30; i >= 1; i--) {
if (sumsei2[i] < 0) {
int cnt = sumsei2[i] / 10 + 1;
sumsei2[i - 1] -= cnt;
sumsei2[i] += 10 * cnt;
}
else if (sumsei2[i] >= 10) {
int cnt = sumsei2[i] / 10;
sumsei2[i] -= cnt * 10;
sumsei2[i - 1] += cnt;
}
}
}
string s;
if (flag) {
for (i = 0; i < 31; i++) {
s.push_back(sumsei[i] + '0');
if (i == 20) {
s.push_back('.');
}
}
while (s[0] == '0') {
s.erase(s.begin());
}
if (s[0] == '.') {
s = '0' + s;
}
cout << s << endl;
}
else {
for (i = 0; i < 31; i++) {
s.push_back(sumsei2[i] + '0');
if (i == 20) {
s.push_back('.');
}
}
while (s[0] == '0') {
s.erase(s.begin());
}
if (s[0] == '.') {
s = '0' + s;
}
cout << '-' << s << endl;
}
}
ふっぴー