Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140610 Change Dating **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/06/10 pm.01:59 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- void function(int, int, int);
- void main()
- {
- printf("Enter a date(yyyy/mm/dd): ");
- char input[10] = {EOF};
- scanf("%[^\n]", input);
- //check input of year
- int check_year = 0;
- int check_counter = 1000;
- for(int i = 0; i < 4; i++)
- {
- check_year += ((int)input[i] - 48) * check_counter;
- check_counter /= 10;
- }
- if(check_year <= 1911)
- {
- printf("Wrong input of year!\n\n");
- exit(1);
- }
- //adjust array element location
- if(input[7] != '/')
- {
- for(int i = 8; i > 4; i--)
- {
- input[i + 1] = input[i];
- }
- input[5] = '0';
- }
- if(input[9] == NULL)
- {
- input[9] = input[8];
- input[8] = '0';
- }
- int year = 0, month = 0, day = 0;
- int counter = 1000;
- for(int i = 0; i < 5; i++)
- {
- year += ((int)input[i] - 48) * counter;
- counter /= 10;
- }
- printf("Output(CNS 7648): ");
- year -= 1911;
- printf("民國");
- if(year > 999)
- {
- function(year, 1000, 0);
- }
- else if(year > 99)
- {
- function(year, 100, 0);
- }
- else if(year > 9)
- {
- function(year, 10, 0);
- }
- else if(year > 0)
- {
- function(year, 1, 0);
- }
- printf("年");
- month = ((int)input[5] - 48) * 10 + ((int)input[6] - 48) * 1;
- if(month > 9)
- {
- function(month, 10, 1);
- }
- else if(month > 0)
- {
- function(month, 1, 1);
- }
- printf("月");
- day = ((int)input[8] - 48) * 10 + ((int)input[9] - 48) * 1;
- if(day > 9)
- {
- function(day, 10, 1);
- }
- else if(day > 0)
- {
- function(day, 1, 1);
- }
- printf("日\n\n");
- system("pause");
- exit(1);
- }
- void function(int data, int counter, int select)
- {
- int temp = data / counter;
- data -= (temp * counter);
- switch(temp)
- {
- case 0:
- printf("零");
- break;
- case 1:
- if((counter == 10) && (select == 1))
- {
- printf("十");
- }
- else
- {
- printf("一");
- }
- break;
- case 2:
- printf("二");
- break;
- case 3:
- printf("三");
- break;
- case 4:
- printf("四");
- break;
- case 5:
- printf("五");
- break;
- case 6:
- printf("六");
- break;
- case 7:
- printf("七");
- break;
- case 8:
- printf("八");
- break;
- case 9:
- printf("九");
- break;
- }
- if(counter == 1)
- return;
- counter = counter / 10;
- function(data, counter, select);
- }
Advertisement
Add Comment
Please, Sign In to add comment