結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-21 10:19:21
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,708 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 25,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 20:54:19
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>

typedef struct{
	char symbol;
	long long int a;
	long long int b;
}DATA;

DATA data[110];

void getNumAndDot(char *s, char *sym, long long int *a, long long int *b){
	int noGetFlag=0;
	int i,sp=0;
	char tc= '+';
	long long int ta=0, tb=0;
	if(s[sp] == '-'){
		tc = '-';
		sp++;
	}
	
	for(; s[sp] != '\0' && s[sp] != '.'; sp++){
		ta= (ta*10) + (int)(s[sp] - '0');
	}
	
	sp+=1;
	
	for(i=0;i<10;i++){
		int num = (int)(s[sp+i] -'0');
		if(s[sp+i] == '\0'){noGetFlag = 1;}
		
		if(noGetFlag == 1){
			num = 0;
		}
		tb = tb*10 + num;
	}
	
	*sym = tc;
	*a = ta;
	*b = tb;
}

void getSum(DATA *a, DATA *b){
	DATA c;
	c.symbol = '+';
	c.a = 0;
	c.b = 0;
	
	if( a->symbol ==  b->symbol ){
		c.symbol = a->symbol;
		
		c.b = c.b + a->b + b->b;
		
		if(c.b >= 10000000000){
			c.b -= 10000000000;
			c.a+=1;
		}
		c.a = c.a + a->a + b->a;
	}else{
		if( (a->a) > (b->a) ){
			if( a->b < b ->b ){
				(a->a) -= 1;
				a->b += 
				10000000000;
			}
		}else if( a->a == b->a && a->b > b->b ){
			
		}else{
			DATA tmp = *a;
			*a = *b;
			*b = tmp;
		}
		
		
		c.b = a->b - b->b;
		c.a = a->a - b->a;
		
		c.symbol = a->symbol;
	}
	
	b->symbol = c.symbol;
	b->a = c.a;
	b->b = c.b;
	
}

int main(void){
	int i,n;
	n=1;
	
	data[0].symbol = '+';
	data[0].a = 0;
	data[0].b = 0;
	
	
	
	scanf("%d", &n);
	for(i=1;i<=n;i++){
		char s[110];
		scanf("%s", s);
		getNumAndDot( s, &data[i].symbol, &data[i].a, &data[i].b);
	}
	
	
	for(i=1;i<=n;i++){
		getSum(&data[i-1], &data[i]);
	}
	
	if(data[n].a == 0 && data[n].b == 0){
		data[n].symbol = '+';
	}
	
	if(data[n].symbol == '+'){
		printf("%lld.%010lld\n", data[n].a, data[n].b);
	}else{
		printf("-%lld.%010lld\n", data[n].a, data[n].b);
	}
	
	return 0;
}
0