求助刚才的T3,只有90分。。
  • 板块灌水区
  • 楼主Terraria
  • 当前回复6
  • 已保存回复6
  • 发布时间2020/11/22 17:10
  • 上次更新2023/11/5 07:31:14
查看原帖
求助刚才的T3,只有90分。。
289275
Terraria楼主2020/11/22 17:10
#include<bits/stdc++.h>
#define int long long
using namespace std;
string s;
string ch1;
string ch2;
int num;
bool hav_ch1=false;
bool hav_ch2=false;
bool hav_num=false;
int pow(int di,int mi){
	int sum=1;
	for(int i=1;i<=mi;i++) sum*=di;
	return sum;
}
signed main(){
	getline(cin,s);
	ch1="";
	ch2="";
	for(int i=0;i<s.size();i++){
		if(!hav_num){
			while(s[i]>='0'&&s[i]<='9'){
				num=num*10+s[i]-'0';
				i++;
			}
			hav_num=true;
		}
		if(hav_num&&!hav_ch1&&!hav_ch2){
			while(s[i]>='A'&&s[i]<='Z'){
				//cout<<1;
				ch1=ch1+s[i];
				i++;
			}
			hav_ch1=true;
		}
		if(hav_num&&hav_ch1&&!hav_ch2){
			i+=2;
			while(s[i]>='A'&&s[i]<='Z'){
				//cout<<2;
				ch2=ch2+s[i];
				i++;
			}
			hav_ch2=true;
		}
	}
	//cout<<endl<<num<<" "<<ch1<<" "<<ch2<<endl;
	if(ch1[0]=='G'){
		if(ch2[0]=='G') cout<<fixed<<setprecision(6)<<num<<endl;
		if(ch2[0]=='M') cout<<fixed<<setprecision(6)<<num*pow(2,10)<<endl;
		if(ch2[0]=='K') cout<<fixed<<setprecision(6)<<num*pow(2,20)<<endl;
		if(ch2[0]=='B') cout<<fixed<<setprecision(6)<<num*pow(2,30)<<endl;
	}
	if(ch1[0]=='M'){
		if(ch2[0]=='G') cout<<fixed<<setprecision(6)<<1.0*num/pow(2,10)<<endl;
		if(ch2[0]=='M') cout<<fixed<<setprecision(6)<<num<<endl;
		if(ch2[0]=='K') cout<<fixed<<setprecision(6)<<num*pow(2,10)<<endl;
		if(ch2[0]=='B') cout<<fixed<<setprecision(6)<<num*pow(2,20)<<endl;
	}
	if(ch1[0]=='K'){
		if(ch2[0]=='G') cout<<fixed<<setprecision(6)<<1.0*num/pow(2,20)<<endl;
		if(ch2[0]=='M') cout<<fixed<<setprecision(6)<<1.0*num/pow(2,10)<<endl;
		if(ch2[0]=='K') cout<<fixed<<setprecision(6)<<num<<endl;
		if(ch2[0]=='B') cout<<fixed<<setprecision(6)<<num*pow(2,10)<<endl;
	}
	if(ch1[0]=='B'){
		if(ch2[0]=='G') cout<<fixed<<setprecision(6)<<1.0*num/pow(2,30)<<endl;
		if(ch2[0]=='M') cout<<fixed<<setprecision(6)<<1.0*num/pow(2,20)<<endl;
		if(ch2[0]=='K') cout<<fixed<<setprecision(6)<<1.0*num/pow(2,10)<<endl;
		if(ch2[0]=='B') cout<<fixed<<setprecision(6)<<num<<endl;
	}
	/*
	switch(ch1){
		case 'GB':
			switch(ch2){
				case 'GB':cout<<fixed<<setprecision(6)<<num<<endl;break;
				case 'MB':cout<<fixed<<setprecision(6)<<num*pow(2,10)<<endl;break;
				case 'KB':cout<<fixed<<setprecision(6)<<num*pow(2,10)<<endl;break;
				case 'B':cout<<fixed<<setprecision(6)<<num*pow(2,10)<<endl;break;
			}
	}
	*/
}
2020/11/22 17:10
加载中...