View Code of Problem 96

#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
	int n;
	char str[5];
	//输入:1个整数n和1个字符串str,0<=n<1000,str=B,KB,MB,GB,TB 
	while(scanf("%d%s", &n, str)){
		if(n==0) break;
		//处理 
		if(strcmp(str, "B")==0){
			printf("0\n");
		}else if(strcmp(str, "KB")==0){
			printf("%.0lf\n", 1.0*n*(1024-1000));
		}else if(strcmp(str, "MB")==0){
			printf("%.0lf\n", 1.0*n*(pow(1024,2)-pow(1000,2)));
		}else if(strcmp(str, "GB")==0){
			printf("%.0lf\n", 1.0*n*(pow(1024,3)-pow(1000,3)));
		}else if(strcmp(str, "TB")==0){
			printf("%.0lf\n", 1.0*n*(pow(1024,4)-pow(1000,4)));
		}
		//输出:1个浮点数(整数不够) 
	}
	
}

Double click to view unformatted code.


Back to problem 96