自己写的代码,发现最后一个测试点过不去
看了这个链接:PAT甲级 1060 Are They Equal (25 分) 题解及几个测试用例_程勇uestc的博客-CSDN博客
添加了 if(flag==1) index[i] = dot - count; 中的if判别,顺利通过测试点 5 0 00.0,成功AC(乐
#include<iostream>
using namespace std;
string reserve[2];
int index[2] = { 0 };
int main() {
string in[2];
int N; cin >> N >> in[0] >> in[1];
for (int i = 0; i < 2; i++) {
reserve[i] = "";
int flag = 0; int count = 0; int dot = in[i].size();
for (int j = 0; j < in[i].size(); j++) {
if (in[i][j] == '.') {
dot = j;
break;
}
}
for (int j = 0; j < in[i].size(); j++) {
if (in[i][j] == '.') continue;
if (in[i][j] != '0') flag = 1;
if (flag == 1) {
reserve[i] += in[i][j];
if (reserve[i].size() == N) break;
}
else count++;
}
if (reserve[i].size() < N)
for (int k = reserve[i].size() + 1; k <= N; k++)
reserve[i] += '0';
if(flag==1) index[i] = dot - count;
}
if (reserve[0] == reserve[1] && index[0] == index[1]) {
cout << "YES 0." << reserve[0] << "*10^" << index[0];
}
else cout << "NO 0." << reserve[0] << "*10^" << index[0] << " 0."
<< reserve[1] << "*10^" << index[1];
return 0;
}