75B - Facetook Priority Wall - CodeForces Solution


expression parsing implementation strings *1500

Please click on ads to support us..

Python Code:

import operator
from collections import OrderedDict
my=input()
value={}
for i in range(int(input())):
	s=input()
	if("posted on" in s):
		a1=s[0:s.find(" posted on")]
		a2=s[s.find("posted on")+10:-7]
		f=3
	elif("commented on" in s):
		a1=s[0:s.find(" commented on")]
		a2=s[s.find("commented on")+13:-7]
		f=2
	else:
		a1=s[0:s.find(" likes ")]
		a2=s[s.find(" likes ")+7:-7]
		f=1
	if(a1==my  or a2==my):
		if(a1 in value):
			value[a1]+=5*f
		else:
			value[a1]=5*f
		if(a2 in value):
			value[a2]+=5*f
		else:
			value[a2]=5*f
	else:
		if(a1 not in value):
			value[a1]=0
		if(a2 not in value):
			value[a2]=0
	value=OrderedDict(sorted(value.items()))
sorted_value=dict(sorted(value.items(),key=operator.itemgetter(1),reverse=True))
for key in sorted_value:
	if(key!=my):
		print(key)

C++ Code:

#include <iostream>
#include <string>
#include<iomanip>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <numeric>
#include<unordered_map>
#include <unordered_set>
#include <cmath>
#include<vector>
#include<algorithm>
#define ll long long
#define endl "\n"
#define GG  ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;
bool ok(ll mid, ll k) {
	return true;
}
ll bs(ll k) {
	ll l = 0, r = 1e10, sum = 0;
	while (l <= r) {
		ll mid = l + (r - l) / 2;
		if (ok(mid, k)) {
			sum = mid;
			l = mid + 1;
		}
		else {
			r = mid - 1;
		}
	}
	return sum;
}
ll gcd(ll n, ll m) {
	if (n == 0 || m == 0) {
		return max(n, m);
	}
	if (n == m) {
		return n;
	}
	return gcd(n % m, m % n);
}
ll lcm(ll n, ll m) {
	return (n / gcd(n, m)) * m;
}
ll fastpower(ll b, ll p) {
	ll halfpower = fastpower(b, p / 2);
	ll res = halfpower * halfpower;
	if (p % 2 != 0) {
		res *= b;
	}
	return res;
}
bool wp(const pair<int, string>& a, const pair<int, string>& b)
{
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return (a.first > b.first);
}
int main() {
	//freopen("hobz.in", "r", stdin);
	//freopen("Round1.in", "r", stdin);
	//freopen("hanya.in", "r", stdin);
	//freopen("tabs.in", "r", stdin);
	GG;
	string s;
	cin >> s;
	ll t;
	cin >> t;
	map<string, ll>mp;
	while (t--) {
		string s1, s2, s3, s4, s5, a = "";
		cin >> s1 >> s2;
		if (s2 == "posted" || s2 == "commented") {
			cin >> s3;
		}
		cin >> s4 >> s5;
		s4.pop_back();
		s4.pop_back();
		a = s4;
		if (s1 == s || a == s) {
			if (s2 == "posted") {
				mp[s1] += 15;
				mp[a] += 15;
			}
			else if (s2 == "commented") {
				mp[s1] += 10;
				mp[a] += 10;
			}
			else if (s2 == "likes") {
				mp[s1] += 5;
				mp[a] += 5;
			}
		}
		mp[s1] += 0;
		mp[a] += 0;
	}
	vector<pair<ll, string>>v;
	for (auto i : mp) {
		if (i.first != s) {
			v.push_back({ i.second,i.first });
		}
	}
	sort(v.begin(), v.end(), wp);
	for (auto i : v) {
		cout << i.second << endl;
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)
2148. Count Elements With Strictly Smaller and Greater Elements
2149. Rearrange Array Elements by Sign
2150. Find All Lonely Numbers in the Array
2151. Maximum Good People Based on Statements
2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting