通过字符串和整型的转换实现。

 1 #include <iostream>
 2 #include <math.h>
 3 using namespace std;
 4 
 5 int main(){
 6     string ss;
 7     int a, b, c = 1, d, e, n;
 8     cin >> ss >> n;
 9     a = stoi(ss);
10     c = pow(10, n);
11     d = a % c;
12     e = a / c;
13     e += d * pow(10, ss.size() - n);
14     double m = (double)e / a;
15     printf("%.2f", m);
16     return 0;
17 }

 

posted on 2022-01-17 14:21  千咲  阅读(66)  评论(0)    收藏  举报