fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <sstream>
  4. using namespace std;
  5. class List{
  6. public:
  7. class Node{
  8. public:
  9. int data;
  10. Node *next;
  11. };
  12. List();
  13. List(const List&);
  14. ~List();
  15. // List& operator=(const List&);
  16. bool empty() const;
  17. void insert(int data,int pos);
  18. void erase(int pos);
  19.  
  20. void traverse();
  21. // Node* linearSearch(int data);
  22. void display();
  23. Node* first;
  24. Node* temp;
  25. private:
  26.  
  27. int mySize;
  28. };
  29. List::~List(){
  30. Node* temp;
  31. Node* record;
  32. record=first;
  33. while(record->next!=NULL){
  34. temp=record;
  35. record=record->next;
  36. delete temp;
  37. }
  38. delete record;
  39. }
  40. List::List():mySize(0),first(NULL){
  41. }
  42. List::List(const List& list){
  43. Node *temp;
  44. temp=list.first;
  45. int i=0;
  46. while(temp->next!=NULL){
  47. this->insert(temp->data,i);
  48. ++i;
  49. temp=temp->next;
  50. }
  51. this->insert(temp->data,i);
  52. }
  53. void List::traverse(){
  54. Node * ptr;
  55. ptr=first;
  56. while(1){
  57. if(ptr->next==NULL){
  58. cout<<ptr->data;
  59. break;
  60. }
  61. else
  62. cout<<ptr->data<<" ";
  63. ptr=ptr->next;
  64. }
  65.  
  66. }
  67. /*Node* List::linearSearch(int data){
  68.   Node* temp;
  69.   temp=first;
  70.   while(1){
  71.   if(temp->data==data)
  72.   return temp;
  73.   else
  74.   temp=temp->next;
  75.   }
  76. }*/
  77. bool List::empty()const{
  78. if(mySize==0)
  79. return true;
  80. else
  81. return false;
  82. }
  83. void List::insert(int data,int pos){
  84. Node* ptr;
  85. Node* temp;
  86. Node* newnode;
  87. newnode=new Node;
  88. if(first==NULL){
  89. first=newnode;
  90. newnode->next=NULL;
  91. newnode->data=data;
  92. ++mySize;
  93. }
  94. else{
  95. if(pos==0){
  96.  
  97. newnode->next=first;
  98. newnode->data=data;
  99. first=newnode;
  100. ++mySize;
  101. }
  102. else if(pos>0&&pos<mySize){
  103. ptr=first;
  104. for(int i=0;i<pos-1;)
  105. ptr=ptr->next;
  106. temp=ptr->next;
  107. ptr->next=newnode;
  108. newnode->next=temp;
  109. newnode->data=data;
  110. ++mySize;
  111. }
  112. else if(pos==mySize){
  113. ptr=first;
  114. while(ptr->next!=NULL)
  115. ptr=ptr->next;
  116. ptr->next=newnode;
  117. newnode->next=NULL;
  118.  
  119. newnode->data=data;
  120. ++mySize;
  121. }
  122. }
  123. }
  124. void List::erase(int pos){
  125. Node* preptr;
  126. Node* deptr;
  127. preptr=first;
  128. for(int i=0;i<pos-2;i++)
  129. preptr=preptr->next;
  130. deptr=preptr->next;
  131. preptr->next=deptr->next;
  132. --mySize;
  133. delete deptr;
  134. }
  135. int main(int argc, char *argv[])
  136. {
  137.  
  138. char temp[10000];
  139. while(cin.getline(temp,10000)){
  140. List constant,x,answer;
  141. int number,tempans=0,countofcons=0,countofx=0,countofans=0,X,tempx=1;
  142. stringstream num(temp);
  143. while(num>>number){
  144. constant.insert(number,countofcons);
  145. ++countofcons;
  146. }
  147. cin.getline(temp,10000);
  148. stringstream num1(temp);
  149. while(num1>>X){
  150. x.insert(X,countofx);
  151. ++countofx;
  152. }
  153. x.temp=x.first;
  154. for(int j=0;j<countofx;++j){
  155. tempx=1,tempans=0;
  156. for(int i=0;i<countofcons-1;++i)
  157. tempx=x.temp->data*tempx;
  158. constant.temp=constant.first;
  159. while(constant.temp->next!=NULL){
  160. tempans=tempans+constant.temp->data*tempx;
  161. constant.temp=constant.temp->next;
  162. tempx=tempx/x.temp->data;
  163. }
  164. tempans=tempans+constant.temp->data;
  165. constant.temp=constant.temp->next;
  166. x.temp=x.temp->next;
  167. answer.insert(tempans,countofans);
  168. ++countofans;
  169. }
  170. answer.traverse();
  171. cout<<endl;
  172. }
  173. return EXIT_SUCCESS;
  174. }
  175.  
Success #stdin #stdout 0.01s 2732KB
stdin
Standard input is empty
stdout
Standard output is empty