PAT (Basic Level) Practice (中文) 1024 科学计数法
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 const int maxn = 100000; 6 char a[maxn]; 7 int main(){ 8 int evalue=0,pos=0,flag=0,ep,len,pointp; 9 int count=0; 10 scanf("%s",a); 11 12 len = strlen(a); 13 for(int i=1;i<len;i++){ 14 if(a[i]=='.'){pointp=i;} 15 if(a[i]=='E') {ep = i;break;} 16 } 17 for(int i=ep+2;i<len;i++){ 18 evalue = evalue * 10 + (a[i]-'0'); 19 } 20 if(a[ep+1]=='+') pos = 1; 21 if(a[0]=='-') printf("%c",a[0]); 22 if(pos==1){ 23 count=0; 24 for(int i=1;i<ep;i++){ 25 if(i>pointp){ 26 if(count<evalue) {printf("%c",a[i]);count++;} 27 else if(count==evalue) printf(".%c",a[i]); 28 else printf("%c",a[i]); 29 } 30 else if(i<pointp) printf("%c",a[i]); 31 } 32 if(count<evalue){ 33 for(int i=count;i<evalue;i++) printf("0"); 34 } 35 } 36 else{ 37 printf("0."); 38 for(int i=1;i<evalue;i++) printf("0"); 39 for(int i=1;i<ep;i++) 40 if(i!=pointp) 41 printf("%c",a[i]); 42 } 43 44 45 46 return 0; 47 }