fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. // Struktura Aktor przechowujaca dane aktora - lista aktorów.
  6. struct Aktor {
  7. string nazwisko; // Imię i nazwisko razem - dla ułatwienia.
  8. int lf; // Liczba fanów, którzy przestaną oglądać serial po odejściu aktora.
  9. Aktor *next; // Wskaźnik na następny element listy.
  10. Aktor(string nazwisko, int lf);
  11. };
  12.  
  13. struct Lista {
  14. Aktor *first; // wskaźnik na poczatek listy
  15. Lista();
  16. void insert_aktor(string nazwisko, int lf);
  17. void find_aktor(int p);
  18. Aktor * AktorSearch(int lfs);
  19. };
  20.  
  21. Aktor::Aktor(string nazwisko, int lf) {
  22. next = NULL;
  23. this->nazwisko = nazwisko;
  24. this->lf = lf;
  25. }
  26.  
  27. Lista::Lista() {
  28. first = NULL;
  29. }
  30.  
  31.  
  32. void Lista::insert_aktor(string nazwisko, int lf) {
  33. Aktor *nowy = new Aktor(nazwisko, lf);
  34. Aktor *pomoc = first, *pomoc2 = NULL; // Wskazniki pomocnicze do poruszania się po liscie.
  35.  
  36. if (first == NULL) {
  37. nowy->next = NULL;
  38. first = nowy;
  39. cout << "TAK" << endl;
  40. }
  41. else {
  42. while ((pomoc != NULL) && ((pomoc->lf) < (nowy->lf))) { // Dopoki nie wyszlismy za liste i aktor na liscie jest przed nowym aktorem, poruszamy sie dalej.
  43. pomoc2 = pomoc; // pomoc2 zawsze wskazuje poprzednika pomoc.
  44. pomoc = pomoc->next;
  45. }
  46. if (pomoc == NULL) {
  47. nowy->next = NULL;
  48. pomoc2->next = nowy;
  49. cout << "TAK" << endl;
  50. }
  51. else if ((pomoc->lf) == (nowy->lf)) {
  52. if (((pomoc->nazwisko) == (nowy->nazwisko))){ // Aktor z podanym nazwiskiem juz istnieje.
  53. cout << "NIE" << endl;
  54. delete nowy; // Usuniecie nowego obiektu aktora
  55. }
  56. else if (((pomoc->nazwisko) < (nowy->nazwisko))) {
  57. //jak nowe nazwisko wieksze:
  58. if (pomoc->next == NULL) {
  59. nowy->next = NULL;
  60. pomoc->next = nowy;
  61. cout << "TAK" << endl;
  62. }
  63. else {
  64. nowy->next = pomoc->next;
  65. pomoc->next = nowy;
  66. cout << "TAK" << endl;
  67. }
  68. }
  69. else {
  70. //jak nowe nazwisko mniejsze:
  71. if (pomoc == first) {
  72. nowy->next = first;
  73. first = nowy;
  74. cout << "TAK" << endl;
  75. }
  76. else{
  77. nowy->next = pomoc;
  78. pomoc2->next = nowy;
  79. cout << "TAK" << endl;
  80. }
  81.  
  82. }
  83. /*else {
  84. if (pomoc->nazwisko > nowy->nazwisko) {
  85. nowy->next = pomoc->next;
  86. pomoc->next = nowy;
  87. cout << "TAK" << endl;
  88. }
  89. else {
  90. if (pomoc == first) {
  91. nowy->next = pomoc;
  92. first = nowy;
  93. cout << "TAK" << endl;
  94. }
  95. else {
  96. nowy->next = pomoc;
  97. pomoc2->next = nowy;
  98. cout << "TAK" << endl;
  99. }
  100. }
  101. }*/
  102. }
  103. else if ((pomoc->lf) < (nowy->lf)) {
  104. // nowy->lf wiekszy:
  105. if (pomoc->next == NULL) {
  106. nowy->next = NULL;
  107. pomoc->next = nowy;
  108. cout << "TAK" << endl;
  109. }
  110. else {
  111. nowy->next = pomoc->next;
  112. pomoc->next = nowy;
  113. cout << "TAK" << endl;
  114. }
  115. }
  116. else {
  117. //jak nowe->lf mniejsze:
  118. if (pomoc == first) {
  119. nowy->next = first;
  120. first = nowy;
  121. cout << "TAK" << endl;
  122. }
  123. else{
  124. nowy->next = pomoc;
  125. pomoc2->next = nowy;
  126. cout << "TAK" << endl;
  127. }
  128. }
  129. }
  130. }
  131.  
  132.  
  133. void Lista::find_aktor(int p){
  134. Aktor *pomoc = first, *pomoc2 = NULL, *pom, *pom2, *out;
  135. bool tmp = true;
  136. if (pomoc == NULL){
  137. cout << "NIE" << endl;
  138. }
  139. else{
  140. while ((pomoc != NULL )) {
  141. if (p <= pomoc->lf){
  142. pom = pomoc;
  143. tmp = true;
  144. break;
  145. }
  146. else{
  147. tmp = false;
  148. }
  149. if (pomoc->next == NULL || pomoc->next->lf > p) {
  150. pom2 = pomoc2;
  151. }
  152.  
  153. pomoc2 = pomoc;
  154. pomoc = pomoc->next;
  155. }
  156. if (tmp == true){
  157.  
  158. if (pom->lf == p) {
  159.  
  160. if (pom == first) {
  161. cout << pom->nazwisko << endl;
  162. first = first->next;
  163. }
  164. else if (pomoc->next == NULL) {
  165. //koniec listy:
  166. cout << pom->nazwisko << endl;
  167. pomoc2->next = NULL;
  168. }
  169. else {
  170. //w srodku:
  171. cout << pom->nazwisko << endl;
  172. pomoc2->next = pom->next;
  173. }
  174. }
  175. else if (pomoc->lf < p) {
  176. cout << pomoc2->nazwisko << endl;
  177. if (pomoc == first) {
  178. pomoc->next = NULL;
  179. first = NULL;
  180. }
  181. else {
  182. pomoc2->next = NULL;
  183. }
  184. }
  185. else if (p < pom->lf){
  186. if (pom == first) {
  187. cout << "NIE" << endl;
  188. }
  189. else {
  190. cout << pomoc2->nazwisko << endl;
  191. if (pomoc2 == first) {
  192. first = pomoc;
  193. }
  194. else {
  195. pom2->next = pomoc;
  196. }
  197. }
  198. }
  199. }
  200. else if (pomoc2->lf < p) {
  201. cout << pomoc2->nazwisko << endl;
  202. if (pomoc2 == first) {
  203. pomoc2->next = NULL;
  204. first = NULL;
  205. }
  206. else {
  207. pom2->next = NULL;
  208. }
  209.  
  210. }
  211. else{
  212. cout << "NIE" << endl;
  213. }
  214. }
  215.  
  216. }
  217.  
  218. Aktor * Lista::AktorSearch(int lfs) {
  219. Aktor *x = first;
  220. while (x != NULL && x->lf != lfs) {
  221. x = x->next;
  222. }
  223. return x;
  224. }
  225.  
  226. int main() {
  227.  
  228. int n; // Liczba operacji do wykonania.
  229. int op; // Rodzaj operacji do wykonania.
  230. int p; // Maksymalna liczba fanów, na której stratę można sobie pozwolić.
  231. int lf;
  232. string nazwisko;
  233.  
  234. cin >> n;
  235.  
  236. Lista *lista = new Lista;
  237.  
  238. for (int i = 0; i < n; i++) {
  239. cin >> op; // Wczytanie rodzaju operacji.
  240. if (op == 1){
  241.  
  242. cin.ignore();
  243. getline(cin, nazwisko);
  244. cin >> lf;
  245.  
  246. lista->insert_aktor(nazwisko, lf);
  247. }
  248. if (op == 2){ // Wyszukanie aktora do roli.
  249. cin.ignore();
  250. cin >> p; // Podaj liczbę fanów, na której stratę możesz sobie pozwolić.
  251. lista->find_aktor(p);
  252. }
  253. }
  254.  
  255. /*lista->insert_aktor("Jurek", 200);
  256. lista->insert_aktor("antek", 100);
  257. lista->insert_aktor("tomek", 400);
  258. lista->insert_aktor("zenek", 200);
  259. lista->insert_aktor("juntek", 300);
  260. lista->insert_aktor("marek", 600);
  261.  
  262. lista->find_aktor(100);
  263. lista->insert_aktor("jozin", 100);
  264.  
  265. cout << lista->first->nazwisko << endl;
  266. cout << lista->first->next->nazwisko << endl;
  267. cout << lista->first->next->next->nazwisko << endl;
  268. cout << lista->first->next->next->next->nazwisko << endl;
  269. cout << lista->first->next->next->next->next->nazwisko << endl;*/
  270.  
  271. //system("pause");
  272. return 0;
  273. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: \35
#include <iostream>
^
Main.java:1: error: class, interface, or enum expected
#include <iostream>
         ^
Main.java:2: error: illegal character: \35
#include <string>
^
Main.java:6: error: class, interface, or enum expected
struct Aktor {
^
Main.java:8: error: class, interface, or enum expected
	int lf;						                // Liczba fan?w, kt?rzy przestan? ogl?da? serial po odej?ciu aktora.
	^
Main.java:9: error: class, interface, or enum expected
	Aktor *next;                                // Wska?nik na nast?pny element listy.
	^
Main.java:10: error: class, interface, or enum expected
	Aktor(string nazwisko, int lf);
	^
Main.java:11: error: class, interface, or enum expected
};
^
Main.java:13: error: class, interface, or enum expected
struct Lista {
^
Main.java:15: error: class, interface, or enum expected
	Lista();
	^
Main.java:16: error: class, interface, or enum expected
	void insert_aktor(string nazwisko, int lf);
	^
Main.java:17: error: class, interface, or enum expected
	void find_aktor(int p);
	^
Main.java:18: error: class, interface, or enum expected
	Aktor * AktorSearch(int lfs);
	^
Main.java:19: error: class, interface, or enum expected
};
^
Main.java:21: error: class, interface, or enum expected
Aktor::Aktor(string nazwisko, int lf) {
^
Main.java:23: error: class, interface, or enum expected
	this->nazwisko = nazwisko;
	^
Main.java:24: error: class, interface, or enum expected
	this->lf = lf;
	^
Main.java:25: error: class, interface, or enum expected
}
^
Main.java:29: error: class, interface, or enum expected
}
^
Main.java:34: error: class, interface, or enum expected
	Aktor *pomoc = first, *pomoc2 = NULL;  // Wskazniki pomocnicze do poruszania si? po liscie.
	^
Main.java:36: error: class, interface, or enum expected
	if (first == NULL) {
	^
Main.java:38: error: class, interface, or enum expected
		first = nowy;
		^
Main.java:39: error: class, interface, or enum expected
		cout << "TAK" << endl;
		^
Main.java:40: error: class, interface, or enum expected
	}
	^
Main.java:44: error: class, interface, or enum expected
			pomoc = pomoc->next;
			^
Main.java:45: error: class, interface, or enum expected
		}
		^
Main.java:48: error: class, interface, or enum expected
			pomoc2->next = nowy;
			^
Main.java:49: error: class, interface, or enum expected
			cout << "TAK" << endl;
			^
Main.java:50: error: class, interface, or enum expected
		}
		^
Main.java:54: error: class, interface, or enum expected
				delete nowy;                    // Usuniecie nowego obiektu aktora
				^
Main.java:55: error: class, interface, or enum expected
			}
			^
Main.java:60: error: class, interface, or enum expected
					pomoc->next = nowy;
					^
Main.java:61: error: class, interface, or enum expected
					cout << "TAK" << endl;
					^
Main.java:62: error: class, interface, or enum expected
				}
				^
Main.java:65: error: class, interface, or enum expected
					pomoc->next = nowy;
					^
Main.java:66: error: class, interface, or enum expected
					cout << "TAK" << endl;
					^
Main.java:67: error: class, interface, or enum expected
				}
				^
Main.java:73: error: class, interface, or enum expected
					first = nowy;
					^
Main.java:74: error: class, interface, or enum expected
					cout << "TAK" << endl;
					^
Main.java:75: error: class, interface, or enum expected
				}
				^
Main.java:78: error: class, interface, or enum expected
					pomoc2->next = nowy;
					^
Main.java:79: error: class, interface, or enum expected
					cout << "TAK" << endl;
					^
Main.java:80: error: class, interface, or enum expected
				}
				^
Main.java:107: error: class, interface, or enum expected
				pomoc->next = nowy;
				^
Main.java:108: error: class, interface, or enum expected
				cout << "TAK" << endl;
				^
Main.java:109: error: class, interface, or enum expected
			}
			^
Main.java:112: error: class, interface, or enum expected
				pomoc->next = nowy;
				^
Main.java:113: error: class, interface, or enum expected
				cout << "TAK" << endl;
				^
Main.java:114: error: class, interface, or enum expected
			}
			^
Main.java:120: error: class, interface, or enum expected
				first = nowy;
				^
Main.java:121: error: class, interface, or enum expected
				cout << "TAK" << endl;
				^
Main.java:122: error: class, interface, or enum expected
			}
			^
Main.java:125: error: class, interface, or enum expected
				pomoc2->next = nowy;
				^
Main.java:126: error: class, interface, or enum expected
				cout << "TAK" << endl;
				^
Main.java:127: error: class, interface, or enum expected
			}
			^
Main.java:135: error: class, interface, or enum expected
	bool tmp = true;
	^
Main.java:136: error: class, interface, or enum expected
	if (pomoc == NULL){
	^
Main.java:138: error: class, interface, or enum expected
	}
	^
Main.java:143: error: class, interface, or enum expected
				tmp = true;
				^
Main.java:144: error: class, interface, or enum expected
				break;
				^
Main.java:145: error: class, interface, or enum expected
			}
			^
Main.java:148: error: class, interface, or enum expected
			}
			^
Main.java:151: error: class, interface, or enum expected
			}
			^
Main.java:154: error: class, interface, or enum expected
			pomoc = pomoc->next;
			^
Main.java:155: error: class, interface, or enum expected
		}
		^
Main.java:162: error: class, interface, or enum expected
					first = first->next;
					^
Main.java:163: error: class, interface, or enum expected
				}
				^
Main.java:167: error: class, interface, or enum expected
					pomoc2->next = NULL;
					^
Main.java:168: error: class, interface, or enum expected
				}
				^
Main.java:172: error: class, interface, or enum expected
					pomoc2->next = pom->next;
					^
Main.java:173: error: class, interface, or enum expected
				}
				^
Main.java:177: error: class, interface, or enum expected
				if (pomoc == first) {
				^
Main.java:179: error: class, interface, or enum expected
					first = NULL;
					^
Main.java:180: error: class, interface, or enum expected
				}
				^
Main.java:183: error: class, interface, or enum expected
				}
				^
Main.java:188: error: class, interface, or enum expected
				}
				^
Main.java:191: error: class, interface, or enum expected
					if (pomoc2 == first) {
					^
Main.java:193: error: class, interface, or enum expected
					}
					^
Main.java:196: error: class, interface, or enum expected
					}
					^
Main.java:202: error: class, interface, or enum expected
			if (pomoc2 == first) {
			^
Main.java:204: error: class, interface, or enum expected
				first = NULL;
				^
Main.java:205: error: class, interface, or enum expected
			}
			^
Main.java:208: error: class, interface, or enum expected
			}
			^
Main.java:213: error: class, interface, or enum expected
		}
		^
Main.java:220: error: class, interface, or enum expected
	while (x != NULL && x->lf != lfs) {
	^
Main.java:222: error: class, interface, or enum expected
	}
	^
Main.java:224: error: class, interface, or enum expected
}
^
Main.java:229: error: class, interface, or enum expected
	int op;						                // Rodzaj operacji do wykonania.
	^
Main.java:230: error: class, interface, or enum expected
	int p;						                // Maksymalna liczba fan?w, na kt?rej strat? mo?na sobie pozwoli?.
	^
Main.java:231: error: class, interface, or enum expected
	int lf;
	^
Main.java:232: error: class, interface, or enum expected
	string nazwisko;
	^
Main.java:234: error: class, interface, or enum expected
	cin >> n;
	^
Main.java:236: error: class, interface, or enum expected
	Lista *lista = new Lista;
	^
Main.java:238: error: class, interface, or enum expected
	for (int i = 0; i < n; i++) {
	^
Main.java:238: error: class, interface, or enum expected
	for (int i = 0; i < n; i++) {
	                ^
Main.java:238: error: class, interface, or enum expected
	for (int i = 0; i < n; i++) {
	                       ^
Main.java:240: error: class, interface, or enum expected
		if (op == 1){
		^
Main.java:243: error: class, interface, or enum expected
			getline(cin, nazwisko);
			^
Main.java:244: error: class, interface, or enum expected
			cin >> lf;
			^
Main.java:246: error: class, interface, or enum expected
			lista->insert_aktor(nazwisko, lf);
			^
100 errors
stdout
Standard output is empty