运用cin特性,简单完成输入。
2026-02-19 22:25:00
发布于:江苏
26阅读
0回复
0点赞
通过观察不难发现,样例的符号、数字、单位之间存在空格,运用cin特性,可以简单的完成输入。
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
for(int i=0;i<n;i++){
int x;string s1,s2,q,p;//q:储存“=”p:储存“?”
cin>>x>>s1>>q>>p>>s2;
long long re=0;
if(s1=="km" and s2=="m"){re=x*1000;}
else if(s1=="km" and s2=="mm"){re=x*1000000;}
else if(s1=="m" and s2=="mm"){re=x*1000;}
else if(s1=="kg" and s2=="g"){re=x*1000;}
else if(s1=="kg" and s2=="mg"){re=x*1000000;}
else if(s1=="g" and s2=="mg"){re=x*1000;}//逐个判断
cout<<x<<' '<<s1<<" = "<<re<<" "<<s2<<endl;//输出
}
}
全部评论 3















































































































2026-03-01 来自 安徽
0



















2026-03-01 来自 安徽
0NB
2026-03-01 来自 安徽
0








有帮助,赞一个