結果
問題 | No.81 すべて足すだけの簡単なお仕事です。 |
ユーザー |
|
提出日時 | 2016-03-31 21:19:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,813 bytes |
コンパイル時間 | 827 ms |
コンパイル使用メモリ | 67,440 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-15 01:04:14 |
合計ジャッジ時間 | 1,787 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 WA * 7 |
ソースコード
#include <iostream> #include <string> #include <sstream> #include <cmath> #include <algorithm> #define SHOW(d) {std::cout << #d << "\t:" << d << "\n";} template<typename T> int GetSign(T x){ if(x==0) return 1; return x/std::abs(x); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n; std::string input, inputInt, inputDec; long long int ansInt = 0, ansDec = 0; std::cin >> n; for(int i=0; i<n; ++i){ std::cin >> input; if(input.find('.') == std::string::npos){ ansInt += static_cast<long long int>(std::stod(input)) + ((input[0]=='-') ? 1 : -1); ansDec += ((input[0]=='-') ? -10000000000 : 10000000000); }else{ std::istringstream ist(input); std::getline(ist, inputInt, '.'); ansInt += static_cast<long long int>(std::stod(inputInt)) + ((input[0]=='-') ? 1 : -1); std::getline(ist, inputDec); while(inputDec.size()<10){ inputDec += '0'; } ansDec += static_cast<long long int>(std::stod(inputDec)) * ((input[0]=='-') ? -1 : 1) + ((input[0]=='-') ? -10000000000 : 10000000000); } } if(GetSign(ansInt)*GetSign(ansDec)<0){ int tmp = GetSign(ansDec); ansInt += ((ansDec/10000000000==0) ? 0 : ansDec/10000000000); ansDec = std::abs(ansDec%10000000000 + 10000000000 * GetSign(ansInt))%10000000000; ansInt += (ansDec==0) ? 0 : tmp; }else{ ansInt += ansDec/10000000000; ansDec = (ansDec + 10000000000) % 10000000000; } inputDec = std::to_string(std::abs(ansDec)); std::cout << ansInt << '.'; for(unsigned int i=0; i<10-inputDec.size(); ++i){ std::cout << '0'; } std::cout << inputDec << "\n"; return 0; }