将数字以字符串形式存储和处理,包含小数处理
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int toint(char n)
{
switch (n)
{
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case '0':
return 0;
default:
return 999999;
}
}
int deletep(string &a) { //运算时消除小数点
string::iterator it;
int i = 0;
for (it = a.end()-1; it != a.begin();it--,i++) {
if (*it == '.') {
a.erase(it);
return i;
}
}
return 0;
}
void deletebackzero(string &a) { //去掉小数末尾的零
string::iterator it;
for (it = a.end() - 1; it != a.begin(); it--) {
if (*it != '0') {
if (*it == '.') { a.eras