Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <list>
- using namespace std;
- #define SIZE 1
- struct dane
- {
- char *from = new char[16];
- char *to = new char[16];
- int kwota = 0;
- void setKwota(int kwota)
- {
- this->kwota = kwota + this->kwota;
- }
- int getKwota()
- {
- return kwota;
- }
- char* getFrom()
- {
- return from;
- }
- char* getTo()
- {
- return to;
- }
- };
- int xd(char *from)
- {
- int sum1 = 0;
- for (int i = 0; i < strlen(from); i++) sum1 = sum1 + from[i];
- return sum1;
- }
- int hashing(char *ppl1, char *ppl2)
- {
- int sum1 = 0;
- int sum2 = 0;
- for (int i = 0; i < strlen(ppl1); i++) sum1 = sum1 + ppl1[i]*i;
- for (int i = 0; i < strlen(ppl2); i++) sum2 = sum2 + ppl2[i]*(strlen(ppl2)-i);
- return (sum1 + sum2) % SIZE;
- }
- int main()
- {
- char opt;
- char *from = new char[16];
- char *to = new char[16];
- int kwota, index;
- list<dane> arr[SIZE];
- while (cin >> opt)
- {
- if (opt == '+')
- {
- int spr = 1;
- cin >> from >> to;
- index = hashing(from, to);
- cin >> kwota;
- list<dane> ::iterator i;
- for (i = arr[index].begin(); i != arr[index].end(); ++i)
- {
- if (i->getFrom() == from && i->getTo() == to)
- {
- cout << "RECHA TO CHUJ" << endl;
- i->setKwota(kwota);
- spr = 0;
- break;
- }
- }
- if (spr == 1)
- {
- dane ar;
- ar.from = from;
- ar.to = to;
- ar.kwota = kwota;
- arr[index].push_back(ar);
- }
- }
- else if (opt == '?')
- {
- int spr = 1;
- cin >> from >> to;
- index = hashing(from, to);
- list<dane> ::iterator i;
- for (i = arr[index].begin(); i != arr[index].end(); ++i)
- {
- if (i->getFrom() == from && i->getTo() == to)
- {
- cout << i->getKwota() << " " << endl <<
- from << " " << i->getFrom() << endl <<
- to << " " << i->getTo() << endl;
- spr = 0;
- break;
- }
- }
- if (spr == 1) cout << 0 << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement