#28955: 有人知道為甚麼這樣子寫是不行的嗎?(我覺得應該是double的問題,但在DEVC++測試時都是正確的)


az07260906 (呢嗎嗎)

學校 : 不指定學校
編號 : 125438
來源 : [61.224.2.106]
最後登入時間 :
2022-01-22 18:31:27
b982. YoJudge 預練(空間之章) -- b961YoJudge | From: [61.224.8.112] | 發表日期 : 2022-01-15 20:12

#include <stdio.h>

#include <string.h>

#include <math.h>

 

int main(){

char s[100];

int i,counter2;

double counter1;

long long int sum;

 

while(scanf("%s", s)!=EOF){

counter1 = counter2 = sum = 0;

 

for(i=0; i<strlen(s); i++){

if(s[i] >= 48 && s[i] <= 57){

counter1 = counter1*10 + (s[i]-'0');

}

else{

if(s[i] == 46 && s[i+2] == 107){

    counter1 += double(s[i+1]-'0')/10;

             i=i+2;

    }

    if(s[i] == 46 && s[i+2] == 98){

    sum += counter1*8 + (s[i+1]-'0');

    i=i+5;

    continue;

}

while(s[i] > 97 && s[i] < 122){

counter2 += s[i];

i++;

}

i = i-1;

if(counter2 == 201 || counter2 == 103){

sum += counter1*pow(10,9)*8;

}

else if(counter2 == 207 || counter2 == 109){

sum += counter1*pow(10,6)*8;

}

else if(counter2 == 205 || counter2 == 107){

sum += counter1*pow(10,3)*8; 

}

else if(counter2 == 436){

sum += counter1*8;

}

else{

sum += counter1;

}

counter1 = counter2 = 0;

}

}

printf("%lld\n", sum);

}

return 0;

}

 
#28957: Re:有人知道為甚麼這樣子寫是不行的嗎?(我覺得應該是double的問題,但在DEVC++測試時都是正確的)


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.9.74.255]
最後登入時間 :
2024-10-14 22:20:08
b982. YoJudge 預練(空間之章) -- b961YoJudge | From: [110.28.40.185] | 發表日期 : 2022-01-16 08:06

    counter1 += double(s[i+1]-'0')/10;


這是C還是C++?如果是C的話,double要括號,改成(double)。你現在這是C++才有的寫法

 
ZeroJudge Forum