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

首頁 > 學院 > 開發設計 > 正文

1060. Are They Equal (25)

2019-11-14 09:39:53
字體:
來源:轉載
供稿:網友

1060. Are They Equal (25)

時間限制 50 ms內存限制 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而且次數為0
3.要考慮小數,不足的位自動補0
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 监利县| 安庆市| 盘山县| 惠州市| 安新县| 永嘉县| 临桂县| 崇阳县| 台湾省| 舒城县| 西乌珠穆沁旗| 彭阳县| 广元市| 肥城市| 通榆县| 民乐县| 抚远县| 通江县| 壶关县| 栾川县| 昂仁县| 深州市| 五河县| 定远县| 年辖:市辖区| 丹江口市| 博野县| 陇南市| 罗定市| 九龙县| 汤阴县| 丰台区| 茌平县| 沂南县| 平乡县| 九龙坡区| 绥芬河市| 三台县| 洛南县| 凉城县| 鄂温|