国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

1060. Are They Equal (25)

2019-11-14 09:07:41
字體:
供稿:網(wǎng)友

1060. Are They Equal (25)

時間限制 50 ms內(nèi)存限制 65536 kB代碼長度限制 16000 B判題程序 Standard 作者 CHEN, Yue

If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123*105 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you are supposed to tell if they are treated equal in that machine.

Input Specification:

Each input file contains one test case which gives three numbers N, A and B, where N (<100) is the number of significant digits, and A and B are the two float numbers to be compared. Each float number is non-negative, no greater than 10100, and that its total digit number is less than 100.

Output Specification:

For each test case, PRint in a line "YES" if the two numbers are treated equal, and then the number in the standard form "0.d1...dN*10^k" (d1>0 unless the number is 0); or "NO" if they are not treated equal, and then the two numbers in their standard form. All the terms must be separated by a space, with no extra space at the end of a line.

Note: Simple chopping is assumed without rounding.

Sample Input 1:
3 12300 12358.9Sample Output 1:
YES 0.123*10^5Sample Input 2:
3 120 128Sample Output 2:
NO 0.120*10^3 0.128*10^3
#include<iostream>#include<string>#include<vector>#include<algorithm>#include<string.h>using namespace std;int y;string exc(string s1,int N){	string s;char c1='0';	int dot=-1,number=-1,fir=0,c=0,i;	for(i=0;i<s1.size();i++){		if(s1[i]=='.')		dot=s1.size()-1-i;		if(s1[i]!='.'&&s1[i]!='0'){			if(fir==0){				fir=1;				number=s1.size()-1-i;			}		}	}	y=number-dot;	if(y<0)	y++;	if(number==-1)	y=0;	for(i=s1.size()-1-number;c<N;i++){		if(i<s1.size())		if(s1[i]!='.'){			s+=s1[i];			c++;		}		else{}		else{			s+=c1;			c++;		}	}	return s;}int main(){	string s1,s2;	int N,i,c,l1,l2;	cin>>N;	cin>>s1>>s2;	s1=exc(s1,N);	l1=y;	s2=exc(s2,N);	l2=y;		if(s1==s2&&l1==l2){		cout<<"YES ";		cout<<"0."<<exc(s1,N)<<"*10^"<<l1; 	} 	else{		cout<<"NO ";		cout<<"0."<<exc(s1,N)<<"*10^"<<l1; 		cout<<" 0."<<exc(s2,N)<<"*10^"<<l2; 	}} 
感想:
1.因為輸入有100位所以要用字符串處理
2.注意如果輸入是0和0.00,要輸出YES而且次數(shù)為0
3.要考慮小數(shù),不足的位自動補(bǔ)0
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 夏河县| 八宿县| 卓尼县| 肇州县| 长海县| 利川市| 重庆市| 宁化县| 彭阳县| 崇明县| 涡阳县| 遂平县| 厦门市| 赞皇县| 西城区| 斗六市| 九龙城区| 东至县| 本溪市| 阳东县| 新泰市| 勃利县| 长武县| 青州市| 鄯善县| 邮箱| 天台县| 广南县| 仪征市| 宿州市| 彝良县| 沧源| 石楼县| 商城县| 炎陵县| 保靖县| 鹤峰县| 八宿县| 遵化市| 晋城| 胶南市|