Giter VIP home page Giter VIP logo

Comments (6)

liuchuo avatar liuchuo commented on July 23, 2024

我为什么觉得就应该读“yi Yi yi Qian er Bai san Shi si”呢……

from pat.

liuchuo avatar liuchuo commented on July 23, 2024

我不会改,要不你把正确代码发Pull Request给我?

from pat.

Li-Boqiang avatar Li-Boqiang commented on July 23, 2024

您好:
这个是我在维基百科上搜到的关于中文数字的读法的相关页面
有如下:
tim 20180622200910

PR的话....我感觉还是直接给你贴代码吧...
VS直接tab的代码风格,渣,见谅。

#include<iostream>
#include<string>
#include<vector>
using namespace std;

string num[10] = { "ling","yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };
string c[6] = { "Ge","Shi", "Bai", "Qian", "Yi", "Wan" };
int J[] = {
    1, 10, 100, 1000,
    10000, 100000, 1000000, 10000000,
    100000000 };
vector<string>res;
void solution()
{
    int n;
    cin >> n;
    if (n==0)
    {
        cout << "ling";
        return;
    }
    if (n<0)
    {
        cout << "Fu ";
        n = -n;
    }
	int part[3];
	part[0]= n / 100000000; 
	part[1]= (n % 100000000) / 10000;
	part[2] = n % 10000;
    bool zero = false;		//是否在非零数字前输出合适的ling
	int printCnt = 0;			//用于维护单词前没有空格,之后输入的单词都在前面加一个空格。
	for (int i = 0; i < 3; i++)
	{
		int temp = part[i];		//三个部分,每部分内部的命名规则都一样,都是X千X百X十X
		for (int j = 3; j >= 0; j--)
		{
			int curPos = 8 - i * 4 + j;			//当前数字的位置
			if (curPos >= 9)
				continue;						//最多九位数
			int cur = (temp / J[j]) % 10;		//取出当前数字
			if (cur!=0)
			{
				if (zero)						//前面有零
				{
					 printCnt++ == 0 ? cout<<"ling" : cout<<" ling";
					 zero = false;
				}
				if (j == 0)
				{
					printCnt++ == 0 ? cout << num[cur] : cout << ' ' << num[cur];		//在个位,直接输出
				}
				else
				{																		//在其他位,还要输出十百千
					printCnt++ == 0 ? cout << num[cur] << ' ' << c[j] : cout << ' ' << num[cur] << ' ' << c[j];
				}
				
			}
			else
			{
				if (!zero&&j != 0 && n / J[curPos] >= 10)			//注意100020这样的情况
				{
					zero = true;
				}
			}
		}
		//处理完每部分之后,最后输出单位,Yi/Wan
		if (i != 2 && part[i]>0)
		{
			cout << ' ' << c[i + 4];
		}
	}
}

int main()
{
    solution();
    return 0;
}

from pat.

liuchuo avatar liuchuo commented on July 23, 2024

写的真好~已将代码更改为你的代码,感谢~

from pat.

Li-Boqiang avatar Li-Boqiang commented on July 23, 2024

...我也是看的别人的代码,女神都是凌晨就起床的么....

from pat.

liuchuo avatar liuchuo commented on July 23, 2024

嗯嗯,我休息的比较早~夏天这个点正好开始天亮,4点开始工作最合适啦

from pat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.