View Code of Problem 96

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
void main(){
  char str[20];
  while(scanf("%s",str)!=EOF){
    if(str[0]=='0') break;
    int len=strlen(str);
    char num[len-2];
    for(int i=0;i<len-2;i++)
      num[i]=str[i];
    int n=atoi(num);
    double m1=0,m2=0;
    if(str[len-2]=='T'){
      m1=n*pow(2,40);m2=n*pow(10,12);
      printf("%.0lf\n",m1-m2);
    }else if(str[len-2]=='G'){
      m1=n*pow(2,30);m2=n*pow(10,9);
      printf("%.0lf\n",m1-m2);
    }else if(str[len-2]=='M'){
      m1=n*pow(2,20);m2=n*pow(10,6);
      printf("%d\n",m1-m2);
    }else if(str[len-2]=='K'){
      m1=n*pow(2,10);m2=n*pow(10,3);
      printf("%d\n",m1-m2);
    }else{
      printf("%d\n",n);
    }
  }
}

Double click to view unformatted code.


Back to problem 96