1060. Are They Equal (25)

点击打开链接


输入为0.0000xxxx的数字,xxx.xxx的也考虑了

但是还有2个点没过

#include <cstdio>
#include <string>
#include <string.h>
using namespace std;
#define  MAX 100010
int n;
//k:c中保存了几位数,
//i:a中读到字符串中的几位数
//cnt
int f(char a[],char c[]){
	int k=0;
	int cnt=0;
	int ans=0;
	if(a[0]=='0'){
		if(a[1]=='.'){
			int i=2;
			while(a[i]=='0'){
				cnt++;
				i++;
			}
			for(;i<strlen(a);i++){
				if(k<n){
					c[k++]=a[i];
				}
				
			}
			c[k]='\0';
			return -cnt;
		}else{
			c="0";
			return 0;
		}

	}else{
		for(int i=0;i<strlen(a);i++){
			if(k<n){
				if(a[i]=='.'){
					ans=cnt;
				}else{
					c[k++]=a[i];
					cnt++;
				}

			}else{
				if(a[i]=='.'){
					break;
				}else{
					cnt++;
				}
			}
		}
		while(k<n){
			c[k++]='0';
		}
		c[k]='\0';
		if(ans!=0){
			return ans;
		}else{
			return cnt;
		}


	}
	
}
int main(){
	freopen("in.txt","r",stdin);
	char  a[MAX],b[MAX],c[MAX],d[MAX];
	while( scanf("%d %s %s",&n,a,b)!=EOF){
		int x=f(a,c);
		int y=f(b,d);
		if(x==y && strcmp(c,d)==0){
			printf("YES 0.%s*10^%d\n",c,x);
		}else{
			printf("NO 0.%s*10^%d 0.%s*10^%d\n",c,x,d,y);
		}
	}
	
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值