zoukankan      html  css  js  c++  java
  • 1002. 写出这个数 (20)

    把一个数串各个数位上的数加起来,然后用给定格式输出,这个输出很有讲究,一个大数从高位向地位输出。
    代码如下:
    #include<iostream>
    using namespace std;
    
    char str[110];
    int res=0,flag=0;
    char output[15][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
    
    void out(int x)
    {
    	if(x>9)
    	{
    		out(x/10);
    	}
    	if(flag)
    	{
    		cout<<" ";
    	}
    	else
    	{
    		flag=1;
    	}
    	cout<<output[x%10];
    }
    
    int main()
    {
    	res=0;
    	flag=0;
    	gets(str);
    	for(int i=0;str[i];i++)
    	{
    		res+=str[i]-'0';
    	}
    	out(res);
    	return 0;
    }
    

      其中大数从高位向低位输出的方法如下:

    void out(int x)
    {
    	if(x>9)
    	{
    		out(x/10);
    	}
    	if(flag)
    	{
    		cout<<" ";
    	}
    	else
    	{
    		flag=1;
    	}
    	cout<<output[x%10];
    }
    

      

  • 相关阅读:
    火柴排队sol
    国王游戏sol
    子串sol
    跳石头
    解方程sol
    花匠sol
    字符串整理
    计算系数
    矩阵取数游戏sol
    8.2_java_28
  • 原文地址:https://www.cnblogs.com/CHLL55/p/4232865.html
Copyright © 2011-2022 走看看