結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー goodbaton
提出日時 2014-11-28 00:48:25
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,159 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 76,764 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-03 09:53:31
合計ジャッジ時間 2,016 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%s",in);
      |         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;




int main(){
    char in[25];
    int sei[13]={0},syo[13]={0},n,p=0,memo[12],me=0;
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        scanf("%s",in);
        
        if(in[0]!='-'){
            me=0;
            for(int j=0;in[j]!='\0' && in[j]!='.';j++){
                memo[j]=in[j]-'0';
                me++;
            }
            
            for(int j=0;j<me;j++){
                sei[me-j-1]+=memo[j];
            }
            
            if(in[me]=='.'){
                for(int j=1;in[j+me]!='\0';j++){
                    syo[j-1]+=in[j+me]-'0';
                }
            }
        }else{
            me=1;
            for(int j=1;in[j]!='\0' && in[j]!='.';j++){
                memo[j]=in[j]-'0';
                me++;
            }
            
            for(int j=0;j<me;j++){
                sei[me-j-1]-=memo[j];
            }
            
            if(in[me]=='.'){
                for(int j=1;in[j+me]!='\0';j++){
                    syo[j-1]-=in[me+j]-'0';
                }
            }
        }
    }
    
    for(int k=0;k<13;k++){
        if(12-k>0 && syo[12-k]>=10){
            syo[11-k]+=syo[12-k]/10;
            syo[12-k]%=10;
        }
        if(12-k>0 && syo[12-k]<0){
            syo[11-k]+=(syo[12-k]+1)/10-1;
            syo[12-k]=syo[12-k]%10+10;
        }
    }
    
    if(syo[0]>=0){
        sei[0]+=syo[0]/10;
        syo[0]%=10;
    }else{
        sei[0]+=(syo[0]+1)/10-1;
        syo[0]=syo[0]%10+10;
    }

    for(int k=0;k<13;k++){
        if(sei[k]>=10){
            sei[k+1]+=sei[k]/10;
            sei[k]%=10;
        }
    }
    
    for(int i=0;i<13;i++){
        if(sei[12-i]>0 || p==1){
            printf("%d",sei[12-i]);
            p=1;
        }
    }
    printf(".");
    for(int i=0;i<10;i++){
        printf("%d",syo[i]);
    }
    
    printf("\n");
    return 0;
}
0