1073. Scientific Notation (20)

全过了,但是!!!

代码写的太挫了,太长了!!!!!

点击打开链接

#include <cstring>
#include <cstdio>
struct s 
{
	char qian[10000];
	char hou[10000];
	int qf;
	int hf;
	int keep;
};
int main(){
	freopen("in.txt","r",stdin);
	char c[10010];
	gets(c);
	s tmp;
	tmp.keep=0;
	for(int i=0;;i++){
		if(c[0]=='+'){
			tmp.qf=1;
		}else{
			tmp.qf=0;
		}
		if(i==1){
			int ii=0;
			int tk=100000;
			for(int j=i;j<strlen(c);j++){

				if(c[j]=='E'){
					tmp.qian[ii]='\0';
					i=j+1;
					break;
				}else{
					if(c[j]=='.'){
						tk=j;
					}
					if(j>tk){
						tmp.keep++;
					}
					tmp.qian[ii++]=c[j];
					
				}
				
			}
			if(c[i]=='+'){
				tmp.hf=1;
			}else{
				tmp.hf=0;
			}
			strcpy(tmp.hou,c+i+1);
			break;
		}
		
	}
	char ans[10000];
	int hh;
	int ca=0;
	sscanf(tmp.hou,"%d",&hh);
	if(tmp.qf==0){
		printf("-");
	}
	if(tmp.hf==1){
		for(int i=0;i<strlen(tmp.qian);i++){
			if(tmp.qian[i]=='.'){
				int cq=0;
				for(int j=i+1;j<strlen(tmp.qian);j++){
					ans[ca++]=tmp.qian[j];
					cq++;
					if(cq==hh){
						if(cq<tmp.keep){
							ans[ca++]='.';
							for(int jj=j+1;jj<strlen(tmp.qian);jj++){
								ans[ca++]=tmp.qian[jj];
							}
							ans[ca]='\0';
							break;
						}
					}
				}
				while(cq!=hh){
					ans[ca++]='0';
					cq++;
				}
				ans[ca++]='\0';
				break;
			}else{
				ans[ca++]=tmp.qian[i];
			}
		}
		printf("%s\n",ans);
	}else{
		for(int i=strlen(tmp.qian)-1;i>=0;i--){	
			if(tmp.qian[i]=='.'){
				int cq=0;
				for(int j=i-1;j>=0;j--){
					cq++;
					ans[ca++]=tmp.qian[j];
				}
				while(cq!=hh){
					ans[ca++]='0';
					cq++;
				}
				ans[ca]='\0';
				break;
			}else{
				ans[ca++]=tmp.qian[i];
			}
		}
		printf("0.");
		for(int i=strlen(ans)-1;i>=0;i--){
			printf("%c",ans[i]);
		}
		printf("\n");
	}
	
	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值