//浮点数分解:符号+整数部分+小数部分+字母e+符号+整数部分
#include <iostream>
#include <string>
using namespace std;
string in;
void cal1(string in, int s, int e) {
char sign = '+';
char c;
int ans = 0;
int casei = s;
if (in[casei] == '+' || in[casei] == '-') {
sign = in[casei];
casei++;
}
while (casei <= e) {
ans = ans * 10 + in[casei] - '0';
casei++;
}
if (sign == '-' && ans) cout << sign; //ans!=0
cout << ans;
}
void cal2(string in, int s, int e) {
int non_zero_bit = -1;
for (int casei = s; casei <= e; casei++) {
if (in[casei] > '0') non_zero_bit = casei;
}
//0012300
if (non_zero_bit != -1) {
cout << '.';
for (int casei = s; casei <= non_zero_bit; casei++) {
cout << in[casei];
}
}
}
void solve1(string in, int s, int e) {
int pos = in.find('.');
cal1(in, 0, pos - 1);
cal2(in, pos + 1, e);
}
void solve2(string in, int s, int e) {
cout << 'e';
cal1(in, s, e);
cout << '\n';
}
int main() {
cin >> in;
int pos = in.find('e');
solve1(in, 0, pos - 1);
solve2(in, pos + 1, in.size() - 1);
return 0;
}
计蒜客之字符串篇
最新推荐文章于 2022-08-21 22:36:02 发布