View Code of Problem 96

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(){
    ios::sync_with_stdio(false);
    string input, tmp;
    int length;
    long long num, numTmp;
    while(cin >> input){
        length = input.length();
        tmp = input.substr(length-2, length);
        if(tmp == "TB"){
            num = 1024;
            num *= 1024;
            num *= 1024;
            num *= 1024;
            numTmp = 1000;
            numTmp *= 1000;
            numTmp *= 1000;
            numTmp *= 1000;
            num -= numTmp;
        }
        else if(tmp == "GB"){
            num = 1024*1024*1024-(1000*1000*1000);
        }
        else if(tmp == "MB"){
            num = 1024*1024-(1000*1000);
        }
        else if(tmp == "KB"){
            num = 1024-1000;
        }
        tmp = input.substr(0, length-2);
        cout << atoi(tmp.c_str())*num << endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 96