View Code of Problem 96

#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main(){
	string kk;
	while(cin>>kk){
		int n=kk.length();
		string danwei=kk.substr(n-2,2);
		int zero=stoi(kk.substr(0,1));
		if(zero==0)
			break;
		if(danwei=="KB"){
			string num=kk.substr(0,n-2);
			int nn=stoi(num);
			long long derta=nn*1024-nn*1000;
			cout<<derta<<endl; 
		}
		else if(danwei=="MB"){
			string num=kk.substr(0,n-2);
			int nn=stoi(num);
			long long derta=nn*1024*1024-nn*1000*1000;
			cout<<derta<<endl; 
		}
		else if(danwei=="GB"){
			string num=kk.substr(0,n-2);
			int nn=stoi(num);
			double derta=nn*pow(1024,3)-nn*pow(1000,3);
			printf("%.0f\n",derta);
		}
		else if(danwei=="TB"){
			string num=kk.substr(0,n-2);
			int nn=stoi(num);
			double derta=nn*pow(1024,4)-nn*pow(1000,4);
			printf("%.0f\n",derta);
		}
		else{
			cout<<0<<endl; 
		}
	}
}

Double click to view unformatted code.


Back to problem 96