C - Dimensions[物理单位运算]
C - Dimensions
题意:模拟物理单位运算化简,然后分成分子分母排序后输出
注意点:(1)符号重载,且它给的序列有一个c的符号错了
(2)如果分子或分母无输出1
(3)纯粹是我个人的问题,要考虑单位反复出现,例如kg*kg
#include
using namespace std;
const int maxn=1e6+5;
#define debug(x) cout<<#x<<':'<='A')||(c<='z'&&c>='a'))
vectorvc;
vectorG[2];
mapmp;
mapmp2;
bool cmp(string c1,string c2){
for(int i=0;i0)mp[temp]++;
else mp[temp]--;
temp="";
}
else if(s[i]=='/'){
// debug(temp);
vc.push_back(temp);
if(tempop>0) mp[temp]++;
else mp[temp]--;
tempop=-1*op;temp="";
}
else if(s[i]=='*'){
//debug(temp);
vc.push_back(temp);
if(tempop>0) mp[temp]++;
else mp[temp]--;
tempop=op;temp="";
}
}
}
int main()
{
string ss="AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
for(int i=0;i>s;
s+='*';
int t=0;
stackk;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]==')') k.push(i);
else if(s[i]=='(') {dp[i]=k.top();k.pop();}
}
// for(int i=0;i0&&vc[i]!=""){G[0].push_back(vc[i]);mp[vc[i]]--;}
}
if(G[1].size()==0) G[1].push_back("1");
if(G[0].size()==0) G[0].push_back("1");
for(int i=0;i