CCF 模拟2-3 找呀找呀找朋友

28 篇文章 0 订阅

在这里插入图片描述
在这里插入图片描述

考试后半段舍友来收拾屋子,不知道满没满 后补的代码…

#include <cstring>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#define ll long long
#define PII pair<int, int>
#define PSI pair<string, int>
#define MSI map<string,int>
#define TLE ios::sync_with_stdio(0),cin.tie(0)
#define mod 1000000007
const int INF = 0x3f3f3f3f;
using namespace std;
struct student {
	string name;
	int num;
}stu[1005];
bool cmp(student a, student b) {
	return a.num > b.num;
}
int main() {
	TLE;
	MSI mp;
	string name, tt;
	cin >> name;
	int n;
	cin >> n; getline(cin, tt);
	while (n--) {
		string str, name1, name2;
		getline(cin, str);
		int flag = 1, t2, t1 = str.find_first_of(' ');
		int w;
		if (str[t1 + 1] == 'r') w = 15;
		else if (str[t1 + 1] == 'c') w = 10;
		else if (str[t1 + 1] == 'l') w = 5;
//		cout << str[t1 + 1] << " t1: " << t1 << endl;
		name1 = str.substr(0, t1);
		t2 = str.find_last_of("'");
		for (int i = t2;; i--) if (str[i] == ' ') {
			name2 = str.substr(i+1, t2 - 1 - i);
			break;
		}
		if (name1 == name) {
			mp[name2] += w;
//			cout << "1" << endl;
		}
		else if (name2 == name) {
			mp[name1] += w;
//			cout << "2" << " w: "<<w<<" "<<mp[name1]<<endl;
		}
		else {
			if (mp[name1] == 0) mp[name1] = 0;
			if (mp[name2] == 0) mp[name2] = 0;
		}
//		cout << name1 << " " << name2 << endl;
	}
	MSI::iterator iter = mp.begin();
	int i = 0;
	while (iter != mp.end()) {
		stu[i].name = iter->first;
		stu[i++].num = iter->second;
		iter++;
	}
	sort(stu,stu+i-1,cmp);
	for (int j = 0; j < i; j++) {
		cout<<stu[j].name<<endl;
	}
	//for (int j = 0; j < i; j++) {
	//	cout << stu[j].num << endl;
	//}
}
/*
yuan
3
cong reply to yuan's message
yuan comment on jack's circle
cong like yuan's circle
*/
/*
circle
3
comment comment on circle's circle
comment comment on circles's circle
nan reply to nang's message
*/
/*
jiangnan
1
comment comment on jiangnan's circle
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值