PAT (Basic Level) Practice (中文)1002

PAT (Basic Level) Practice (中文)1002_第1张图片

 

#include 

int main()
{
  char n[100];
  scanf("%s",&n);
  
  int i = 0;
  int a = 0;
  while(n[i] != '\0')
  {
  	a = a + n[i] - 48;
  	i++;	   
  }
  
  i = 0;
  int temp = 0;
  int num[4] = {0};
  
  while(a >= 10)
  {
  	temp = a % 10;
  	a = a / 10;
    num[i] = temp;
    i++;
    
  }
  num[i] = a;
  int j = 0;
  int s = 0;
  for(j = i; j >= 0; j--)
  {
  	switch(num[j])
  	{ 
  		case 0:
  			printf("ling");
  			break;
  		case 1:
  			printf("yi");
  			break;
  		case 2:
  			printf("er");
  			break;
  		case 3:
  			printf("san");
  			break;
  		case 4:
  			printf("si");
  			break;
  		case 5:
  			printf("wu");
  			break;
  		case 6:
  			printf("liu");
  			break;
  		case 7:
  			printf("qi");
  			break;
  		case 8:
  			printf("ba");
  			break;
  		case 9:	
  			printf("jiu");
  			break;
  		default:
  			break;
  	} 
  	if(j != 0)
		printf(" ");  
  }
  
    
  return 0;
}

 

你可能感兴趣的:(C语言)