fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int counter=0;
  4. struct pokemon{
  5. int pokedex=0;
  6. int damage;
  7. int health;
  8. int level=1;
  9. pokemon *next=nullptr;
  10. pokemon *prev=nullptr;
  11.  
  12. };
  13. void discard(pokemon *temp)
  14. {
  15. if(temp->pokedex==0)
  16. return;
  17. else
  18. {
  19.  
  20. temp->prev->next=temp->next;
  21. temp->next->prev=temp->prev;
  22.  
  23. counter-=1;
  24. delete temp;
  25. }
  26.  
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32. pokemon *head;
  33. head = new pokemon;
  34. pokemon *current=head;
  35. pokemon *target=nullptr;
  36. int number;
  37. cin>>number;
  38. for(int y=0;y<number;y++)
  39. {
  40. //current=head->prev;j
  41. int pokedex,damage,health;
  42. string command;
  43. int length;
  44. string state;
  45. cin>>command;
  46. if(command=="Insert")
  47. {
  48. cin>>pokedex>>damage>>health>>state;
  49. pokemon *newpoke= new pokemon;
  50. current->next=newpoke;
  51. newpoke->prev=current;
  52. newpoke->next=head;
  53. head->prev=newpoke;
  54. current=newpoke;
  55. newpoke->pokedex=pokedex;
  56. newpoke->damage=damage;
  57. newpoke->health=health;
  58. counter+=1;
  59. if(target==nullptr)
  60. {
  61. target=newpoke;
  62. //cout<<"this is target"<<endl;
  63. }
  64.  
  65. if(state=="Evolve")
  66. {
  67. if(counter<3)
  68. goto end;
  69. if(newpoke->next->next->pokedex==newpoke->pokedex&&newpoke->prev->pokedex==newpoke->pokedex)
  70. {
  71. pokemon *left=newpoke->prev;
  72. pokemon *right=newpoke->next->next;
  73. if(left->level<3&&right->level<3)
  74. {
  75. int maxlevel=max(left->level,right->level);
  76. int maxhp=max(left->health,right->health);
  77. maxhp=max(maxhp,newpoke->health);
  78. int maxdamage=max(left->damage,right->damage);
  79. maxdamage=max(maxdamage,newpoke->damage);
  80. target->health=maxhp;
  81. target->damage=maxdamage;
  82. target->level=(maxlevel+1);
  83. //newpoke->prev->prev->next=head;
  84. current=newpoke->prev->prev;
  85. discard(newpoke->prev);
  86. discard(newpoke);
  87.  
  88.  
  89. }
  90. else
  91. goto end;
  92. }
  93. else
  94. goto end;
  95.  
  96. }
  97. else if(state=="Attack")
  98. {
  99. if(newpoke==target)
  100. goto end;
  101. if(counter<3)
  102. {
  103. newpoke->prev->health-=newpoke->damage;
  104. if(newpoke->prev->health<1)
  105. {
  106. discard(newpoke->prev);
  107. target=newpoke;
  108. }
  109. goto end;
  110. }
  111. newpoke->next->next->health-=newpoke->damage;
  112. newpoke->prev->health-=newpoke->damage;
  113. if(newpoke->prev->health<1)
  114. discard(newpoke->prev);
  115. if(newpoke->next->next->health<1)
  116. {
  117. target=target->next;
  118. discard(target->prev);
  119. current=head->prev;
  120.  
  121. }
  122.  
  123. goto end;
  124.  
  125. }
  126. else
  127. goto end;
  128. }
  129.  
  130. else if(command=="Delete")
  131. {
  132. if (target==nullptr)
  133. goto end;
  134. else if(target->pokedex==0)
  135. goto end;
  136. else if(counter==1)
  137. {
  138. //cout<<"haha"<<endl;
  139.  
  140. //pokemon *temp=target;
  141. target=nullptr;
  142. //cout<<"it works!"<<endl;
  143. //delete temp;
  144. head->next=nullptr;
  145. head->prev=nullptr;
  146. counter--;
  147. current=head;
  148. goto end;
  149. }
  150. else
  151. {
  152. pokemon *temp=target->next;
  153. if(target==current)
  154. current=target->prev;
  155. discard(target);
  156. target=temp;
  157.  
  158. }
  159.  
  160. }
  161. else if (command=="Shuffle")
  162. {
  163. string direction;
  164. cin>>direction>>length;
  165. length%=counter;
  166. if(length==0)
  167. length=counter;
  168. if(direction=="c")
  169. {
  170.  
  171. pokemon *temp=target;
  172. if(target->pokedex==0||length==1)
  173. goto end;
  174. for(int i=0;i<length-1;i++)
  175. {
  176. if(temp->pokedex==0)
  177. i-=1;
  178. temp=temp->next;
  179. }
  180. int temppokedex,tempdamage,temphealth,templevel;
  181. temppokedex=temp->pokedex;
  182. templevel=temp->level;
  183. tempdamage=temp->damage;
  184. temphealth=temp->health;
  185. temp->pokedex=target->pokedex;
  186. temp->level=target->level;
  187. temp->damage=target->damage;
  188. temp->health=target->health;
  189. target->pokedex=temppokedex;
  190. target->level=templevel;
  191. target->damage=tempdamage;
  192. target->health=temphealth;
  193. pokemon *temp2=temp;
  194. target->prev=head->prev;
  195. head->prev->next=target;
  196. target=temp;
  197. head->prev=target->prev;
  198. target->prev->next=head;
  199. target->prev=head;
  200. head->next=target;
  201. current=head->prev;
  202.  
  203. }
  204. else if(direction=="a")
  205. {
  206. pokemon *temp=target;
  207. if(target->pokedex==0||length==1)
  208. goto end;
  209. if(length==2)
  210. temp=temp->prev->prev;
  211. else
  212. {
  213. for(int i=0;i<length-1;i++)
  214. {
  215. if(temp->pokedex==0)
  216. i-=1;
  217. temp=temp->prev;
  218. }
  219. }
  220.  
  221. int temppokedex,tempdamage,temphealth,templevel;
  222. temppokedex=temp->pokedex;
  223. templevel=temp->level;
  224. tempdamage=temp->damage;
  225. temphealth=temp->health;
  226. temp->pokedex=target->pokedex;
  227. temp->level=target->level;
  228. temp->damage=target->damage;
  229. temp->health=target->health;
  230. target->pokedex=temppokedex;
  231. target->level=templevel;
  232. target->damage=tempdamage;
  233. target->health=temphealth;
  234. pokemon *temp2=temp;
  235. target->prev=head->prev;
  236. head->prev->next=target;
  237. target=temp;
  238. head->prev=target->prev;
  239. target->prev->next=head;
  240. target->prev=head;
  241. head->next=target;
  242. current=head->prev;
  243.  
  244. }
  245. }
  246.  
  247. else if(command=="Check")
  248. {
  249. cin>>length;
  250. if(length<2)
  251. goto end;
  252. int count[101]={0};
  253. pokemon *temp=target;
  254. for(int i=0;i<length && temp->pokedex!=0;i++)
  255. {
  256. count[temp->pokedex]+=1;
  257. temp=temp->next;
  258. }
  259. temp=target;
  260. for(int i=0;i<length && temp->pokedex!=0;i++)
  261. {
  262. if(count[temp->pokedex]>1)
  263. {
  264. if(counter==1)
  265. {
  266. delete target;
  267. target=nullptr;
  268. head->next=nullptr;
  269. head->prev=nullptr;
  270. current=head;
  271. counter--;
  272. goto end;
  273. }
  274. if(temp==target)
  275. target=temp->next;
  276. if(temp==current)
  277. current=temp->prev;
  278. pokemon *temp2=temp->next;
  279. discard(temp);
  280. temp=temp2;
  281. }
  282. else
  283. temp=temp->next;
  284. }
  285.  
  286. }
  287.  
  288. else if (command == "Reverse")
  289. {
  290.  
  291. cin >> length;
  292. pokemon *front=target;
  293. for(int i=counter;i>0;i-=length)
  294. {
  295. int round;
  296. if(i>length)
  297. round=length;
  298. else
  299. round=i;
  300. vector<pokemon*>temps;
  301. pokemon *temp=front;
  302. for(int b=0;b<round;b++)
  303. {
  304. temps.emplace_back(temp);
  305. temp=temp->next;
  306. }
  307. temps[round-1]->prev=temps[0]->prev;
  308. temps[round-1]->prev->next=temps[round-1];
  309. temps[0]->next=temps[round-1]->next;
  310. temps[0]->next->prev=temps[0];
  311. for(int b=round-1;b>0;b--)
  312. {
  313. temps[b]->next=temps[b-1];
  314. temps[b-1]->prev=temps[b];
  315. }
  316. if(front==target)
  317. {
  318. target=temps[round-1];
  319. }
  320. if(temps[round-1]==current)
  321. current=temps[0];
  322. front=temps[0]->next;
  323.  
  324. }
  325.  
  326.  
  327.  
  328. }
  329. end:
  330. pokemon *temp=target;
  331. if(temp==nullptr)
  332. {
  333. cout<<"no Poke Poke ;-;"<<endl;
  334. continue;
  335. }
  336.  
  337.  
  338. while(temp->pokedex!=0)
  339. {
  340. cout<<"ID:"<<temp->pokedex<<" HP:"<<temp->health<<" LVL:"<<temp->level<<"->";
  341. temp=temp->next;
  342. }
  343. cout<<endl;
  344. }
  345.  
  346. if(target==nullptr)
  347. cout<<"no Poke Poke ;-;"<<endl;
  348. else
  349. {
  350. while(target->pokedex!=0)
  351. {
  352. cout<<"ID: "<<target->pokedex<<" HP: "<<target->health<<" LVL: "<<target->level;
  353. target=target->next;
  354. cout<<endl;
  355. }
  356. }
  357. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
no Poke Poke ;-;