ответ:
uses graphabc;
var xx,yy,u: integer;
procedure growl(x,y,r: integer);
var i: byte;
begin
for i: =1 to r do
begin
circle(x,y,i);
sleep(5);
end;
end;
procedure growr(x,y: integer);
var i: byte;
begin
for i: =1 to 20 do
begin
ellipse(x-5,y-(i),x-(i*3),y+(i));
ellipse(x+5,y-(i),x+(i*3),y+(i));
ellipse(x-(i),y-5,x+(i),y-(i*3));
ellipse(x-(i),y+5,x+(i),y+(i*3));
sleep(3);
end;
end;
procedure fall;
var r,prer,i: byte;
x,y: integer;
begin
for i: =1 to 10 do
begin
x: =random(160)-80+windowwidth div 2;
prer: =0;
r: =random(10)+10;
for y: =80+windowheight div 2 to windowheight+30 do
begin
setpencolor(clwhite);
circle(x,y-1,prer);
setpencolor(clblack);
circle(x,y,r);
prer: =r;
sleep(3);
end;
end;
end;
procedure growd (x,y: integer);
var i: byte;
begin
for i: =20 downto 5 do
begin
clearwindow;
setbrushcolor(clgreen);
ellipse(x-5,y-(20),x-(60),y+(20));
ellipse(x+5,y-(20),x+(60),y+(20));
ellipse(x-(20),y-5,x+(20),y-(60));
ellipse(x-(20),y+5,x+(20),y+(60));
setbrushcolor(rgb(255,255-((20-i)*10),255-((20-i)*;
circle(x-i,y-i,i);
circle(x+i,y-i,i);
circle(x+i,y+i,i);
circle(x-i,y+i,i);
sleep(5);
end;
end;
var j: integer;
begin
repeat
setbrushcolor(clgreen);
growr(windowwidth div 2,windowheight div 2);
setbrushcolor(clwhite);
for j: =1 to 360 do
if j mod 10=0 then
begin
xx: =round(windowwidth div 2+20*cos(pi*(u+(j*10))/180));
yy: =round(windowheight div 2+20*sin(pi*(u+(j*10))/180));
growl(xx,-j) div 10));
end;
sleep(100);
fall;
growd (windowwidth div 2,windowheight div 2);
sleep(100);
until false;
end.
объяснение:
Опубликовал решение на PasteBin и тут, поскольку суда криво копируются символы таба, и потом нельзя нормально скопировать код. https://pastebin.com/kWSChLsh
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct State {
vector<pair<string, int>> candidates; // кандидаты в этом штате
string state; // название штата
int weight; // "вес" штата
State(string state = " ", int weight = 0) : state(state), weight(weight) {
}
void vote(string candidate) { // принимаем голос избирателя
if (candidates.size() == 0) {
candidates.push_back({ candidate, 1 });
return;
}
for (int i = 0; i < candidates.size(); ++i) {
if (candidates[i].first == candidate) {
++candidates[i].second;
break;
}
else if (i == candidates.size() - 1) {
candidates.push_back({ candidate, 0 });
}
}
}
string getResultOfElections() {
if (candidates.size() == 1) {
return candidates[0].first;
}
sort(candidates.begin(), candidates.end(), // сортировка по голосам
[](pair<string, int>& a, pair<string, int>& b) {
return (a.second > b.second);
});
int last = -1;
for (int i = 1; i < candidates.size(); ++i) { // убираем проигравших
if (candidates[i].second != candidates[0].second) {
last = i;
break;
}
}
if (last != -1)
candidates.erase(candidates.begin() + last);
sort(candidates.begin(), candidates.end(), // лексографическая сортировка
[](pair<string, int>& a, pair<string, int>& b) {
return strcmp(a.first.c_str(), b.first.c_str()) < 0;
});
return candidates[0].first; // победитель
}
};
int main() {
setlocale(LC_ALL, "Russian");
cout << "Введите количество штатов: ";
vector<State> states;
int nOfStates = 0;
cin >> nOfStates;
cin.ignore();
cout << "Введите данные о состоянии штатов в формате Название_штата Значимость_Штата: ";
for (int i = 1; i <= nOfStates; ++i) {
string input, buffer, name, weight;
getline(cin, input);
name = input.substr(0, input.find(' '));
weight = input.substr(input.find(' '));
states.push_back(State(name, stoi(weight)));
}
cout << "Количество голосов: ";
int nOfVotes = 0;
cin >> nOfVotes;
cin.ignore();
cout << "Данные о голосах в формате Штат Кандидат: ";
for (int i = 0; i < nOfVotes; ++i) {
string input, state, candidate;
getline(cin, input);
state = input.substr(0, input.find(' '));
candidate = input.substr(input.find(' ') + 1);
for (int j = 0; j < nOfStates; ++j) {
if (states[j].state == state) {
states[j].vote(candidate);
}
}
}
vector<pair<string, int>> winners;
for (int i = 0; i < states.size(); ++i) {
string result = states[i].getResultOfElections();
if (winners.size() == 0) {
winners.push_back({ result, states[i].weight });
continue;
}
for (int j = 0; j < winners.size(); ++j) {
if (winners[j].first == result) {
winners[j].second += states[i].weight;
break;
}
else if (j == winners.size() - 1) {
winners.push_back({ result, 0 });
}
}
}
cout << endl;
for (int i = 0; i < winners.size(); ++i) {
cout << winners[i].first << " " << winners[i].second << endl;
}
}