蓝桥&搜狐畅游 单位转换 枚举

33 阅读1分钟

image.png image.png image.png

思想

一共就给了"B","KB","MB"三个单位,因此我们可以枚举一下。

注意点: 转换单位之后数值可能比较大,所以需要开LL。

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

typedef long long LL;
int t;
int main()
{
  cin>>t;
  while(t--)
  {
    LL x,y;
    string s;
    cin>>x>>s>>y;
    if(s=="B")cout<<x/y<<endl;
    if(s=="KB")cout<<x*1024/y<<endl;
    if(s=="MB")cout<<x*1024*1024/y<<endl;
  }


  return 0;
}