hihocoder1566http://hihocoder.com/problemset/problem/1566

一直WA因为cmp的写法写错了,未能正确实现排序功能。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<iterator>
#include<queue>
#include<cctype>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 0x3f3f3f3f
#define MAXN 100010
const int MOD=1e9+;
typedef long long ll;
using namespace std;
int t;
typedef struct {
char s1[], s2[];
int sum;
}Node;
Node node[];
map<char, int> mp;
int cal(const char s[])
{
int len = strlen(s), ans=, last=mp[s[len-]];
for(int i = len-; i >= ; i--){
if(last-mp[s[i]] > ){
last -= mp[s[i]];
}
else{
ans += last;
last = mp[s[i]];
}
}
ans += last;
return ans;
}
bool cmp(const Node a, const Node b)
{
if(strcmp(a.s1, b.s1) != ) return strcmp(a.s1, b.s1)<;
else{
return a.sum < b.sum;
}
}
int main()
{
IO;
mp['I']=;mp['V']=;mp['X']=;mp['L']=;mp['C']=;mp['D']=;mp['M']=;
cin >> t;
for(int i = ; i < t; i++){
cin >> node[i].s1 >> node[i].s2;
node[i].sum = cal(node[i].s2);
//cout << cal(node[i].s2) << endl;
}
sort(node, node+t, cmp);
for(int i = ; i < t; i++){
cout << node[i].s1 << " " << node[i].s2 << endl;
}
return ;
}
05-11 11:06
查看更多