1060 Are They Equal (25point(s)) 需要二刷 *科学计数法得处理问题

基本思想:

主要是指数计算,通过去除先导零来进行情况枚举,注意一下;

 

关键点:

无;

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
using namespace std;

int n;

string charge(string s,int& e) {
	int k = 0;
	while (s.length() > 0 && s[0] == '0') {
		s.erase(s.begin());
	}
	if (s[0] == '.') {
		//如果是小数;
		s.erase(s.begin());
		while (s.length() > 0 && s[0] == '0') {
			s.erase(s.begin());
			e--;
		}
		//找到非零得第一位小数;
	}
	else {
		//如果不是小数;
		//需要寻找小数点;
		while (k < s.length() && s[k] != '.') {
			k++;
			e++;
		}
		//此时k为小数点或者结尾;
		if (k < s.length()) {
			//如果k位小数点;
			s.erase(s.begin() + k);
		}
	}
	int num = 0;
	k = 0;
	string res;
	while (num < n) {
		if (k < s.length())
			res += s[k++];
		else
			res += '0';
		num++;
	}
	return res;
}

int main() {
	string a, b;
	cin>>n >> a >> b;
	int e1 = 0, e2 = 0;
	string s1 = charge(a, e1);
	string s2 = charge(b, e2);
	if (s1 == s2 && e1 == e2) {
		cout << "YES 0." << s1 << "*10^" << e1 << endl;
	}
	else {
		cout << "NO 0." << s1 << "*10^" << e1 <<" 0." << s2 << "*10^" << e2 << endl;
	}
	return 0;
}

  

posted @ 2020-02-21 15:02  暮云林凌  阅读(131)  评论(0)    收藏  举报