Holey_yan

20140610_KUAS_VisualC++_ChangeDating

Jun 10th, 2014
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. /************************************/
  2. /** 20140610 Change Dating         **/
  3. /** Maker  : Yan                   **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2014/06/10 pm.01:59   **/
  6. /************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. void function(int, int, int);
  12. void main()
  13. {
  14.     printf("Enter a date(yyyy/mm/dd): ");
  15.     char input[10] = {EOF};
  16.     scanf("%[^\n]", input);
  17.  
  18.     //check input of year
  19.     int check_year = 0;
  20.     int check_counter = 1000;
  21.     for(int i = 0; i < 4; i++)
  22.     {
  23.         check_year += ((int)input[i] - 48) * check_counter;
  24.         check_counter /= 10;
  25.     }
  26.     if(check_year <= 1911)
  27.     {
  28.         printf("Wrong input of year!\n\n");
  29.         exit(1);
  30.     }
  31.  
  32.     //adjust array element location
  33.     if(input[7] != '/')
  34.     {
  35.         for(int i = 8; i > 4; i--)
  36.         {
  37.             input[i + 1] = input[i];
  38.         }
  39.         input[5] = '0';
  40.     }
  41.     if(input[9] == NULL)
  42.     {
  43.         input[9] = input[8];
  44.         input[8] = '0';
  45.     }
  46.  
  47.     int year = 0, month = 0, day = 0;
  48.     int counter = 1000;
  49.     for(int i = 0; i < 5; i++)
  50.     {
  51.         year += ((int)input[i] - 48) * counter;
  52.         counter /= 10;
  53.     }
  54.    
  55.     printf("Output(CNS 7648): ");
  56.  
  57.     year -= 1911;
  58.     printf("民國");
  59.     if(year > 999)
  60.     {
  61.         function(year, 1000, 0);
  62.     }
  63.     else if(year > 99)
  64.     {
  65.         function(year, 100, 0);
  66.     }
  67.     else if(year > 9)
  68.     {
  69.         function(year, 10, 0);
  70.     }
  71.     else if(year > 0)
  72.     {
  73.         function(year, 1, 0);
  74.     }
  75.  
  76.     printf("年");
  77.     month = ((int)input[5] - 48) * 10 + ((int)input[6] - 48) * 1;
  78.     if(month > 9)
  79.     {
  80.         function(month, 10, 1);
  81.     }
  82.     else if(month > 0)
  83.     {
  84.         function(month, 1, 1);
  85.     }
  86.     printf("月");
  87.  
  88.     day = ((int)input[8] - 48) * 10 + ((int)input[9] - 48) * 1;
  89.     if(day > 9)
  90.     {
  91.         function(day, 10, 1);
  92.     }
  93.     else if(day > 0)
  94.     {
  95.         function(day, 1, 1);
  96.     }
  97.  
  98.     printf("日\n\n");
  99.     system("pause");
  100.     exit(1);
  101. }
  102.  
  103. void function(int data, int counter, int select)
  104. {
  105.     int temp = data / counter;
  106.     data -= (temp * counter);
  107.     switch(temp)
  108.     {
  109.         case 0:
  110.             printf("零");
  111.             break;
  112.         case 1:
  113.             if((counter == 10) && (select == 1))
  114.             {
  115.                 printf("十");
  116.             }
  117.             else
  118.             {
  119.                 printf("一");
  120.             }
  121.             break;
  122.         case 2:
  123.             printf("二");
  124.             break;
  125.         case 3:
  126.             printf("三");
  127.             break;
  128.         case 4:
  129.             printf("四");
  130.             break;
  131.         case 5:
  132.             printf("五");
  133.             break;
  134.         case 6:
  135.             printf("六");
  136.             break;
  137.         case 7:
  138.             printf("七");
  139.             break;
  140.         case 8:
  141.             printf("八");
  142.             break;
  143.         case 9:
  144.             printf("九");
  145.             break;
  146.     }
  147.     if(counter == 1)
  148.         return;
  149.     counter = counter / 10;
  150.     function(data, counter, select);
  151. }
Advertisement
Add Comment
Please, Sign In to add comment