1082 Read Number in Chinese (25 分)

A1082

#include 
#include
int main() {
	char num[][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
	char wei[][20]={"Shi","Bai","Qian","Wan","Yi"};
	char str[11];
	int left=0, right;
	scanf("%s", &str); 
	int len=strlen(str);
	if(str[0]=='-'){
		printf("Fu");
		left++;
	}
		right=len-1;
		while(left+4<=right){
			right-=4;
		}
		while(left0&&str[left]=='0'){
					flag1=true;
				}else{
					if(flag1==true){
					printf(" ling");
					flag1=false;
					}
				if(left>0)printf(" ");
				printf("%s",num[str[left]-'0']);
				flag2=true;
				if(left!=right){
					printf(" %s",wei[right-1-left]);
				}
				} 
				left++;
			} 
		    if(flag2==true&&right!=len-1){
		    	printf(" %s", wei[(len-right-1)/4+2]);
			}  
			right+=4;
		}	
	return 0;
} 

 

你可能感兴趣的:(advanced_pat)