ÇÁ·Î±×·¡¹Ö

 3200, 1/160 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   karicoru89
   c¾ð¾î Áø¼ö º¯È¯ ÄÚµùÁßÀä...

http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=6390 [º¹»ç]


À쫆 ̴¿¡ ÁÖ¾îÁø ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© ÇÁ·Î±×·¥À» ¿Ï¼ºÇÏ´Â °Çµ¥¿ä...
ÀÏ´Ü ÁÖ¾ðÁø ÇÔ¼ö°¡ ....
int getIntNum(char firstCharacter)
{
     int num = 0;
     int value;
     char ch;
     if (firstCharacter != '0')
     {
         ch = firstCharacter;
         do
         {
             num = 10*num + (int)(ch-'0');
             ch = getchar();
         }while(isdigit(ch));
     }
     else
     {
         ch = getchar();
         if((ch>='0')&&(ch <='7'))
             do
             {
                 num = 8*num + (int)(ch-'0');
                 ch = getchar();
             }while((ch>='0')&&(ch <='7'));
             else if ((ch == 'X') || (ch=='x'))
             {
                 while((value = hexValue(ch=getchar())) != -1)
                     num = 16 * num + value ;
             }
             else num = 0;
     }
     ungetc(ch , stdin);
     return num;
}
int hexValue(char ch)
{
     switch(ch){
     case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
         return (ch - '0');
     case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
         return (ch - 'A'+10);
     case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
         return (ch - 'a'+10);
     default:
         return -1;
     }
}


Àä....À̰ÍÀ» ¾î¶»°Ô ¿Ï¼ºÇؾߵdzª¿ä??

  Hit : 5085     Date : 2013/10/07 10:59



    
hch19860906 ¾Æ·¡¿Í °°ÀÌ ¿Ï¼ºÇÏ½Ã¸é µË´Ï´Ù.
#include <stdio.h>
#include <ctype.h>

int hexValue(char ch) // 10ÀÌ»óÀÇ ¼ýÀÚ¸¦ A,B,C,D,E,F·Î ¹Ù²Ù´Â ÇÔ¼ö
{
switch(ch){
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':
return (ch - '0');
case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
return (ch - 'A'+10);
case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
return (ch - 'a'+10);
default:
return -1;
}
}

int getIntNum(char firstCharacter) // firstCharacter¿¡ µû¶ó 10Áø¼ö, 8Áø¼ö, 16Áø¼öÀΰ¡¸¦ ÆÇº°ÇÕ´Ï´Ù.
// firstCharacter°¡ 0À̸é 8Áø¼ö, 0ÀÌ°í ±×´ÙÀ½¹®ÀÚ°¡ xÀ̸é 16Áø¼ö
// firstCharacter°¡ 0ÀÌ ¾Æ´Ñ ¼ýÀÚÀ̸é 10Áø¼ö·Î ÆÇº°ÇÏ¿© 10Áø¼ö°ªÀ» °è»êÇÕ´Ï´Ù.
{
int num = 0;
int value;
char ch;
if (firstCharacter != '0')
{
ch = firstCharacter;
do
{
num = 10*num + (int)(ch-'0');
ch = getchar();
}while(isdigit(ch));
}
else
{
ch = getchar();
if((ch>='0')&&(ch <='7'))
do
{
num = 8*num + (int)(ch-'0');
ch = getchar();
}while((ch>='0')&&(ch <='7'));
else if ((ch == 'X') || (ch=='x'))
{
while((value = hexValue(ch=getchar())) != -1)
num = 16 * num + value ;
}
else num = 0;
}
ungetc(ch , stdin);
return num;
}

int main()
{
char firstcharacter;
int nDecimal;
firstcharacter = getchar();
nDecimal = getIntNum(firstcharacter);
printf("Decimal number is %d\n", nDecimal);
return 0;
}
2013/11/16