跳到正文

题解

题解:AT_past202303_b 小数点第 D 位

longlongandint约 8 分钟
原文
文章信息与版本

文章信息

收录
2025年12月31日
更新
2026年7月25日
篇幅
约 8 分钟

版本

  1. v1当前

c++

本人第一篇题解(大家都太麻烦了吧!).

**c_str()可以把string转成”字符串”**所以代码如下

C++
#include<bits/stdc++.h>
using namespace std;
double a,b,c;
string d,ans;
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>d>>a>>b;
    c=a+b;
    ans="%."+d+"lf";//加上%.dlf;
    printf(ans.c_str(),c);//转
return 0;
}

如果你是在不会你可以用打表,前提d不能太大(d<=100不是很大)

C++
#include<bits/stdc++.h>
using namespace std;
double d,a,b,c;//c是a+b的和
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>d>>a>>b;
    c=a+b;
    int i=1;
    if(d==i)printf("%.1lf",c);
    else if(d==2)printf("%.2lf",c);
    else if(d==3)printf("%.3lf",c);
    else if(d==4)printf("%.4lf",c);
    else if(d==5)printf("%.5lf",c);
    else if(d==6)printf("%.6lf",c);
    else if(d==7)printf("%.7lf",c);
    else if(d==8)printf("%.8lf",c);
    else if(d==9)printf("%.9lf",c);
    else if(d==10)printf("%.10lf",c);
    else if(d==11)printf("%.11lf",c);
    else if(d==12)printf("%.12lf",c);
    else if(d==13)printf("%.13lf",c);
    else if(d==14)printf("%.14lf",c);
    else if(d==15)printf("%.15lf",c);
    else if(d==16)printf("%.16lf",c);
    else if(d==17)printf("%.17lf",c);
    else if(d==18)printf("%.18lf",c);
    else if(d==19)printf("%.19lf",c);
    else if(d==20)printf("%.20lf",c);
    else if(d==21)printf("%.21lf",c);
    else if(d==22)printf("%.22lf",c);
    else if(d==23)printf("%.23lf",c);
    else if(d==24)printf("%.24lf",c);
    else if(d==25)printf("%.25lf",c);
    else if(d==26)printf("%.26lf",c);
    else if(d==27)printf("%.27lf",c);
    else if(d==28)printf("%.28lf",c);
    else if(d==29)printf("%.29lf",c);
    else if(d==30)printf("%.30lf",c);
    else if(d==31)printf("%.31lf",c);
    else if(d==32)printf("%.32lf",c);
    else if(d==33)printf("%.33lf",c);
    else if(d==34)printf("%.34lf",c);
    else if(d==35)printf("%.35lf",c);
    else if(d==36)printf("%.36lf",c);
    else if(d==37)printf("%.37lf",c);
    else if(d==38)printf("%.38lf",c);
    else if(d==39)printf("%.39lf",c);
    else if(d==40)printf("%.40lf",c);
    else if(d==41)printf("%.41lf",c);
    else if(d==42)printf("%.42lf",c);
    else if(d==43)printf("%.43lf",c);
    else if(d==44)printf("%.44lf",c);
    else if(d==45)printf("%.45lf",c);
    else if(d==46)printf("%.46lf",c);
    else if(d==47)printf("%.47lf",c);
    else if(d==48)printf("%.48lf",c);
    else if(d==49)printf("%.49lf",c);
    else if(d==50)printf("%.50lf",c);
    else if(d==51)printf("%.51lf",c);
    else if(d==52)printf("%.52lf",c);
    else if(d==53)printf("%.53lf",c);
    else if(d==54)printf("%.54lf",c);
    else if(d==55)printf("%.55lf",c);
    else if(d==56)printf("%.56lf",c);
    else if(d==57)printf("%.57lf",c);
    else if(d==58)printf("%.58lf",c);
    else if(d==59)printf("%.59lf",c);
    else if(d==60)printf("%.60lf",c);
    else if(d==61)printf("%.61lf",c);
    else if(d==62)printf("%.62lf",c);
    else if(d==63)printf("%.63lf",c);
    else if(d==64)printf("%.64lf",c);
    else if(d==65)printf("%.65lf",c);
    else if(d==66)printf("%.66lf",c);
    else if(d==67)printf("%.67lf",c);
    else if(d==68)printf("%.68lf",c);
    else if(d==69)printf("%.69lf",c);
    else if(d==70)printf("%.70lf",c);
    else if(d==71)printf("%.71lf",c);
    else if(d==72)printf("%.72lf",c);
    else if(d==73)printf("%.73lf",c);
    else if(d==74)printf("%.74lf",c);
    else if(d==75)printf("%.75lf",c);
    else if(d==76)printf("%.76lf",c);
    else if(d==77)printf("%.77lf",c);
    else if(d==78)printf("%.78lf",c);
    else if(d==79)printf("%.79lf",c);
    else if(d==80)printf("%.80lf",c);
    else if(d==81)printf("%.81lf",c);
    else if(d==82)printf("%.82lf",c);
    else if(d==83)printf("%.83lf",c);
    else if(d==84)printf("%.84lf",c);
    else if(d==85)printf("%.85lf",c);
    else if(d==86)printf("%.86lf",c);
    else if(d==87)printf("%.87lf",c);
    else if(d==88)printf("%.88lf",c);
    else if(d==89)printf("%.89lF",c);
    else if(d==90)printf("%.90lf",c);
    else if(d==100)printf("%.100lf",c);
return 0;
}

有错请说,不喜勿喷!

原文
存档评论1 条抓取于