View Code of Problem 96

#include <iostream>
#include <map>
#define DIVIDEN 10e16
using namespace std;

double n;
string dw;
map<string, int> change;

int main() {
	change["KB"] = 1;
	change["MB"] = 2;
	change["GB"] = 3;
	change["TB"] = 4;
	cin >> n;
	while(n != 0.0) {
		double sum1 = n / DIVIDEN;
		double sum2 = sum1;
		cin >> dw;
		for(int i = 1; i <= change[dw]; i++) {
			sum1 *= 1024;
			sum2 *= 1000;
		}
		printf("%.0lf\n", (sum1 - sum2) * DIVIDEN);
//		cout << (sum1 - sum2) * DIVIDEN << endl;
		cin >> n;
	}	
	return 0;
}

Double click to view unformatted code.


Back to problem 96