PAT1073. Scientific Notation (20)

#include <iostream>
using namespace std;
string a;
int expo;
int dotPos;
int expoPos;
int i;
int main(){
	cin>>a;
	if(a[0]=='+'||a[0]=='-'){
		if(a[0]=='-'){cout<<"-";}
		a.erase(a.begin());
	}
	for(i=0;i<a.size();i++){
		if(a[i]=='.'){
			dotPos=i;
		}
		if(a[i]=='E'){
			expoPos=i;
			break;
		}
	}
	string expoStr=a.substr(expoPos+1);
	expo=stoi(expoStr);
	string b=a.substr(0,expoPos);
	b.erase(b.begin()+dotPos);
	if(expo>0){
		if((expoPos-dotPos)<=(expo+1)){
			cout<<b;
			int count=expo-(expoPos-dotPos)+1;
			while(count--){cout<<"0";}
		}else{
			int i=0;
			i+=expo+1;
			b.insert(i,".");
			cout<<b<<endl;
		}	
	}else if(expo<0){
		expo++;
		cout<<"0.";
		while(expo!=0){
			cout<<"0";
			expo++;
		}
		cout<<b<<endl;
	}else{
		cout<<a.substr(0,expoPos);
	}


    return 0;
}

 

posted @ 2016-03-27 21:03  Yellowman  阅读(130)  评论(0编辑  收藏  举报
TVRBMExqRXlPQzR5TXpjdU1UVTEK\n