#12869: 為什麼不行


timmy940410 (遊艇)

學校 : 臺北市私立延平高級中學
編號 : 69053
來源 : [122.116.197.27]
最後登入時間 :
2021-02-19 11:39:00
d561. 被秒殺的四捨五入 -- jack1 | From: [220.132.118.119] | 發表日期 : 2017-10-25 21:39

#include<iostream>
#include<iomanip>
using namespace std;
int main(){
double x;
cin>>x;
cout <<fixed<<setprecision(2)<<x<<endl;
}

 

這樣寫在DEVC++執行可以

 
#12872: Re:為什麼不行


sponge (qd)

學校 : 不指定學校
編號 : 21007
來源 : [114.42.160.159]
最後登入時間 :
2023-10-30 16:12:32
d561. 被秒殺的四捨五入 -- jack1 | From: [61.223.36.204] | 發表日期 : 2017-10-26 14:14

#include
#include
using namespace std;
int main(){
double x;
cin>>x;
cout <<fixed<<setprecision(2)<<x<<endl;
}

 

這樣寫在DEVC++執行可以



d561. 被秒殺的四捨五入 -- jack1
×

查看評分詳細結果。

 
hint
Complete
Close
AC (1ms, 702KB)
×

查看程式碼 #364516

jack1
sub ok(byval strx as string)
    dim f as string = trim(strx) & "00000"
    dim v as integer = instr(f,".")
    
    dim s as string = mid(f,1,v-1)
    
    dim i as integer = val(mid(f,v+1,1))
    dim j as integer = val(mid(f,v+2,1))
    dim k as integer = val(mid(f,v+3,1))
    if k > 4 then j += 1
    if j > 9 then
        j -= 10
        i += 1
    end if
    if i > 9 then
        i -= 10
        if instr(s,"-") > 0 then
            s = "-1"
        else
            s = "1"
        end if    
    end if    
    dim o as string = s & "." & str(i) & str(j)
    if o = "-0.00" then o = "0.00"
    print o
end sub

dim s as string
open cons for input as #1
do 
   
    input #1, s
  
    if trim(s)<>"" then 
        ok(s)
    end if
loop until eof(1)
Close
×

查看程式碼 #364516

jack1
solutioncode
Close
BASIC
2009-12-07 14:29

basic 也可以耶

 
#12884: Re:為什麼不行


timmy940410 (遊艇)

學校 : 臺北市私立延平高級中學
編號 : 69053
來源 : [122.116.197.27]
最後登入時間 :
2021-02-19 11:39:00
d561. 被秒殺的四捨五入 -- jack1 | From: [220.132.118.119] | 發表日期 : 2017-10-28 20:25

#include
#include
using namespace std;
int main(){
double x;
cin>>x;
cout <<setprecision(2)<<fixed<<x<<endl;
}

 上一篇寫錯寫錯

位置要對調過來

這樣寫在DEVC++執行可以



d561. 被秒殺的四捨五入 -- jack1
×

查看評分詳細結果。

 
hint
Complete
Close
AC (1ms, 702KB)
×

查看程式碼 #364516

jack1
sub ok(byval strx as string)
    dim f as string = trim(strx) & "00000"
    dim v as integer = instr(f,".")
    
    dim s as string = mid(f,1,v-1)
    
    dim i as integer = val(mid(f,v+1,1))
    dim j as integer = val(mid(f,v+2,1))
    dim k as integer = val(mid(f,v+3,1))
    if k > 4 then j += 1
    if j > 9 then
        j -= 10
        i += 1
    end if
    if i > 9 then
        i -= 10
        if instr(s,"-") > 0 then
            s = "-1"
        else
            s = "1"
        end if    
    end if    
    dim o as string = s & "." & str(i) & str(j)
    if o = "-0.00" then o = "0.00"
    print o
end sub

dim s as string
open cons for input as #1
do 
   
    input #1, s
  
    if trim(s)<>"" then 
        ok(s)
    end if
loop until eof(1)
Close
×

查看程式碼 #364516

jack1
solutioncode
Close
BASIC
2009-12-07 14:29

basic 也可以耶




 
ZeroJudge Forum