창고의 응용 ---10진수를 다른 진수로 변환
                                            
 12017 단어  창고의 응용10진수를 다른 진수로 변환
                    
  
  
  
  
   
   
   
   - //  .cpp : Defines the entry point for the console application.  
- //  
-  
- #include "stdafx.h"  
- #include <stdio.h>  
- #include <stdlib.h>  
- #define OK 1  
- #define ERROR 0  
- #define OVERFLOW -2  
- #define LISTINCREMENT 10  
- #define INFEASIBLE -1  
- #define STACK_INIT_SIZE 100  
- #define STACKINCREMENT 10  
- typedef int SElemType;  
- typedef int Status;  
- typedef int ElemType;  
- typedef struct SqStack  
- {  
-  SElemType *base;  
-  SElemType *top;  
-  int stacksize;  
- }SqStack;  
-  
- Status InitStack(SqStack &S);  
- Status Push(SqStack &S,SElemType e);  
- Status Pop(SqStack &S,SElemType &e);  
- Status StackEmpty(SqStack S);  
- void convert(int e);  
- void CONVERT(int integer,int N);  
-  
- int _tmain(int argc, _TCHAR* argv[])  
- {  
-     int n;  
-     printf(" :");  
-     scanf("%d",&n);  
-     CONVERT(n,2);  
-     scanf("%d",&n);  
-     return 0;  
- }  
-  
-  
- void CONVERT(int integer,int N)  
- {     
-     SqStack S;  
-     InitStack(S);  
-     int e;  
-     while(integer)  
-     {  
-       Push(S,integer % N);  
-       integer = integer/N;  
-     }  
-     printf(" %d :",N);  
-     while(!StackEmpty(S))  
-     {  
-       Pop(S,e);  
-       convert(e);  
-     }  
- }  
-        
- void convert(int e)  
- {  
-  if(e==0)  
-   printf("0");  
-  if(e==1)  
-   printf("1");  
-  if(e==2)  
-   printf("2");  
-  if(e==3)  
-   printf("3");  
-  if(e==4)  
-   printf("4");  
-  if(e==5)  
-   printf("5");  
-  if(e==6)  
-   printf("6");  
-  if(e==7)  
-   printf("7");  
-  if(e==8)  
-   printf("8");  
-  if(e==9)  
-   printf("9");  
-  if(e==10)  
-   printf("A");  
-  if(e==11)  
-   printf("B");  
-  if(e==12)  
-   printf("C");  
-  if(e==13)  
-   printf("D");  
-  if(e==14)  
-   printf("E");  
-  if(e==15)  
-   printf("F");  
- }   
-     
- Status InitStack(SqStack &S)  
- {  
-  S.base = (SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));  
-  if(!S.base)  
-   exit(OVERFLOW);  
-  S.top = S.base;  
-  S.stacksize=STACK_INIT_SIZE;  
-  return OK;  
- }  
-  
- Status Pop(SqStack &S,SElemType &e)  
- {  
-  if(S.top == S.base)  
-   return ERROR;  
-   e = *--S.top;  
-  return OK;  
- }  
-  
-  
- Status Push(SqStack &S,SElemType e)  
- {  
-  if(S.top - S.base >= S.stacksize)  
-  {  
-   S.base = (ElemType *)realloc(S.base,(S.stacksize + LISTINCREMENT) * sizeof(ElemType));  
-   if(!S.base)  
-    exit(OVERFLOW);  
-   S.top = S.base + S.stacksize;  
-   S.stacksize += STACKINCREMENT;  
-   }  
-  *S.top++ = e;  
-   return OK;  
- }  
-  
- Status StackEmpty(SqStack S)  
- {  
-  if(S.top == S.base)  
-   return OK;  
-  else 
-  return ERROR;  
- }