Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- typedef struct node{
- struct node* next;
- int order;
- int value;
- }QNode;
- typedef QNode * QNodePtr;
- void main(int argc,char*argv[]){
- QNode*head,*tail;
- int i,order,value;
- head=NULL;
- tail=head;
- for(i=0;i<argc-1;i++){
- if(argv[i+1][0]=='x'){
- dequeue(&head,&tail);
- }else{
- value=atoi(argv[i+1]);
- order=atoi(argv[i+1]);
- enqueue(&head,&tail,order,value);i++;
- }
- }
- }
- int enqueue(QNodePtr* head, QNodePtr* tail, int order,int value){
- QNode *new_node=(QNode*)malloc(sizeof(QNode));
- if(new_node){
- new_node->value=value;
- new_node->order=order;
- new_node->next=NULL;
- if(*head==NULL) *head=new_node;
- else (*tail)->next=new_node;
- *tail=new_node;
- }
- }
- int dequeue(QNodePtr *head,QNodePtr *tail){
- int value;
- QNodePtr t=*head;
- if(*head==NULL){printf("NO FOOD\n");
- }else if(*head!=NULL && *tail!=NULL || *head!=*tail){
- int value= t->value;
- int order= t->order;
- *head= t->next;
- free(t);
- *head=NULL;
- price(&order,&value);
- }else{
- int value= t->value;
- int order= t->order;
- *head= t->next;
- free(t);
- price(&order,&value);}
- return value;
- }
- int price(int order, int value){
- int mon,cost;
- if(order==1){
- printf("100(Ramen)%d=%d\n",value,value*100);
- printf("Pay : ");
- scanf("%d\n",mon);
- if(mon>=cost){
- printf("change : %d\n",mon-cost);
- }
- }
- if(order==2){
- printf("20(Somtum)%d=%d\n",value,value*20);
- printf("Pay : \n");
- scanf("%d\n",mon);
- if(mon>=cost){
- printf("change : %d\n",mon-cost);
- }
- }
- if(order==3){
- printf("50(Fried chicken)%d=%d\n",value,value*50);
- printf("Pay : \n");
- scanf("%d\n",mon);
- if(mon>=cost){
- printf("change : %d\n",mon-cost);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement