Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. typedef struct node{
  5. struct node* next;
  6. int order;
  7. int value;
  8. }QNode;
  9. typedef QNode * QNodePtr;
  10.  
  11. void main(int argc,char*argv[]){
  12. QNode*head,*tail;
  13. int i,order,value;
  14. head=NULL;
  15. tail=head;
  16. for(i=0;i<argc-1;i++){
  17. if(argv[i+1][0]=='x'){
  18. dequeue(&head,&tail);
  19. }else{
  20. value=atoi(argv[i+1]);
  21. order=atoi(argv[i+1]);
  22. enqueue(&head,&tail,order,value);i++;
  23. }
  24. }
  25. }
  26. int enqueue(QNodePtr* head, QNodePtr* tail, int order,int value){
  27. QNode *new_node=(QNode*)malloc(sizeof(QNode));
  28. if(new_node){
  29. new_node->value=value;
  30. new_node->order=order;
  31. new_node->next=NULL;
  32. if(*head==NULL) *head=new_node;
  33. else (*tail)->next=new_node;
  34. *tail=new_node;
  35. }
  36. }
  37. int dequeue(QNodePtr *head,QNodePtr *tail){
  38. int value;
  39. QNodePtr t=*head;
  40. if(*head==NULL){printf("NO FOOD\n");
  41. }else if(*head!=NULL && *tail!=NULL || *head!=*tail){
  42. int value= t->value;
  43. int order= t->order;
  44. *head= t->next;
  45. free(t);
  46. *head=NULL;
  47. price(&order,&value);
  48. }else{
  49. int value= t->value;
  50. int order= t->order;
  51. *head= t->next;
  52. free(t);
  53. price(&order,&value);}
  54. return value;
  55. }
  56. int price(int order, int value){
  57. int mon,cost;
  58. if(order==1){
  59. printf("100(Ramen)%d=%d\n",value,value*100);
  60. printf("Pay : ");
  61. scanf("%d\n",mon);
  62. if(mon>=cost){
  63. printf("change : %d\n",mon-cost);
  64. }
  65. }
  66. if(order==2){
  67. printf("20(Somtum)%d=%d\n",value,value*20);
  68. printf("Pay : \n");
  69. scanf("%d\n",mon);
  70. if(mon>=cost){
  71. printf("change : %d\n",mon-cost);
  72. }
  73. }
  74. if(order==3){
  75. printf("50(Fried chicken)%d=%d\n",value,value*50);
  76. printf("Pay : \n");
  77. scanf("%d\n",mon);
  78. if(mon>=cost){
  79. printf("change : %d\n",mon-cost);
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement