結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー cureskolcureskol
提出日時 2020-04-06 16:33:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,377 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 172,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 22:51:26
合計ジャッジ時間 3,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void f(string &s){
  int now=0;
  while(now<s.size()&&s[now]!='.')now++;
  if(now==s.size()){
    s.push_back('.');
    for(int i=0;i<10;i++)s.push_back('0');
  }
  else{
    int A=s.size();
    for(int i=0;i<10-(A-now)+1;i++)s.push_back('0');
  }
}
string ans="0.0000000000";
void h(string a,string b,int mi){
  string res;int pre=0;
  if(!mi)swap(a,b);
  for(int i=0;i<10;i++){
    char A=a[a.size()-1-i],B=b[b.size()-1-i];
    if(pre)A-=1;pre=0;
    if(A<B){A+=10;pre=1;}
    res.push_back(A-B+'0');
  }
  res.push_back('.');
  for(int i=11;i<b.size();i++){
    char A=a[a.size()-1-i],B=b[b.size()-1-i];
    if(pre)A-=1;pre=0;
    if(A<B){A+=10;pre=1;}
    res.push_back(A-B+'0');
  }
  for(int i=b.size();i<a.size();i++){
    char A=a[a.size()-1-i];
    if(pre)A-=1;pre=0;
    if(A<'0')A+=10,pre=1;
    res.push_back(A);
  }
  if(res.back()=='0'&&res.size()>12)res.pop_back();
  if(mi)res.push_back('-');
  reverse(res.begin(),res.end());
  ans=res;
}
void g(string a,string b){
  int mi=0;
  if(a[0]=='-'&&b[0]=='-'){
    mi=1;
    a=a.substr(1,a.size()-1);
    b=b.substr(1,b.size()-1);
  }
  else if(a[0]=='-'){
    a=a.substr(1,a.size()-1);
    if(a.size()>b.size())mi=1;
    else if(a.size()==b.size()){
      for(int i=0;i<a.size();i++){
        if(a[i]>b[i])mi=1;
        if(a[i]<b[i])break;
      }
    }
    h(a,b,mi);return;
  }
  else if(b[0]=='-'){
    swap(a,b);
    a=a.substr(1,a.size()-1);
    if(a.size()>b.size())mi=1;
    else if(a.size()==b.size()){
      for(int i=0;i<a.size();i++){
        if(a[i]>b[i])mi=1;
        if(a[i]<b[i])break;
      }
    }
    h(a,b,mi);return;
  }

  if(a.size()<b.size())swap(a,b);
  string res;
  int pre=0;
  for(int i=0;i<b.size();i++){
    if(i==10){res.push_back('.');continue;}
    char A=a[a.size()-1-i],B=b[b.size()-1-i];
    char C=(char)(A-'0'+B-'0'+pre);
    pre=0;
    if(C>9)C-=10,pre=1;
    res.push_back((char)(C+'0'));
  }
  for(int i=b.size();i<a.size();i++){
    char A=a[a.size()-1-i];
    char C=(char)(A-'0'+pre);
    pre=0;
    if(C>9)C-=10,pre=1;
    res.push_back((char)(C+'0'));
  }
  if(pre)res.push_back('1');
  if(mi)res.push_back('-');
  reverse(res.begin(),res.end());
  ans=res;
}

signed main(){
  int n;cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  for(string &p:s)f(p);
  for(string &p:s)g(ans,p);
  cout<<ans<<endl;
}
0