Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- int find(string* arr, int lenght, string name) {
- for (int i = 0; i < lenght; i++)
- if (arr[i] == name)
- return i; // &arr[i]
- return -1;
- }
- int main() {
- ifstream in ("f1.txt");
- string* names = NULL;
- int* points = NULL;
- string temp;
- int pCount = 0, operations = 0;
- getline(in, temp);
- pCount = stoi(temp);
- names = new string[pCount];
- points = new int[pCount];
- for (int i = 0; i < pCount; i++) {
- getline(in, names[i]);
- points[i] = 0;
- }
- getline(in, temp);
- operations = stoi(temp);
- int from, to; int transfer;
- char c;
- for (int i = 0; i < operations; i++) {
- in >> temp;
- from = find(names, pCount, temp);
- in >> temp;
- to = find(names, pCount, temp);
- in >> temp;
- if (from == -1 || to == -1 || temp == "")
- continue;
- transfer = stoi(temp);
- points[from] -= transfer;
- points[to] += transfer;
- }
- in.close();
- ofstream out("f2.txt");
- for (int i = 0; i < pCount; i++)
- out << names[i] << " " << points[i] << endl;
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement