View Code of Problem 96

#include <bits/stdc++.h>
using namespace std;
#define N 1000
#define M 1024
map<string , int> mp;
int main()
{
	string str;
	mp["B"]=0;
	mp["KB"]=1;
	mp["MB"]=2;
	mp["GB"]=3;
	mp["TB"]=4;
	while(cin>>str) {
		string num,dw;
		num = str.substr(0,str.length()-2);
		dw = str.substr(str.length()-2,str.length());
		if(num=="0")	break;
//		cout<<num<<" "<<dw;
		long long bit1,bit2;
		sscanf(num.c_str(),"%lld",&bit1);
//		cout<<bit;
		bit2=bit1;
		for(int i=1;i<=mp[dw];i++){
			bit1*=N;
			bit2*=M;
		}
		cout<<bit2-bit1<<endl;	
		
		
	} 
	return 0;
 } 

Double click to view unformatted code.


Back to problem 96