Basic exercises - the number of readings


title: the number of basic exercises readings
categories:

  • ACM
  • Logical
    tags:
  • Reading the word
    date: 2020-03-14 17:21:46

Look at the title of the scale, up to one billion units. Chinese digital unit has a characteristic, a ten Facing a group, if set, $ 110 set. A number that is read first reading in front of a ten million Baiqian readings, then add billion and then read 100000000-10000 of a ten Baiqian readings, then reread million and then read a ten heavenly. For example, 1234567890, first read front billion figure, twelve, then add million digital reading between the EVA million for, three thousand four hundred fifty-six, then add million and then read seven thousand eight hundred ninety final reading 1,234,567,890. There are some other details.

problem

The number of basic questions to practice pronunciation

By submitting this question

Resource constraints

Time limit: 1.0s Memory Limit: 512.0MB

Problem Description

Professor Tom is to teach a graduate course on genes, one thing made him quite a headache: there are tens of thousands of base pairs on a chromosome, they are numbered from 0 to millions, tens of millions, or billions.
  For example, when the students about the bases at position No. 1234567009, the light looks figures are difficult to accurately read out.
  So, he desperately needs a system, and then when he entered 1,234,567,009 time, will give the corresponding read the law:
  1,234,567,009
  represented as Pinyin
  shi er yi san qian si bai wu shi liu wan qi qian ling jiu
  so he only needs to read shining on it.
  Your task is to help him design a system like this: Given a string of digits, you help him into reading and writing Chinese Pinyin string accordance with the norms of the adjacent two syllables with a lattice open spaces.
  Note must be in strict accordance with specifications, such as "10010" is read as "yi wan ling yi shi" instead of "yi wan ling shi", " 100000" is read as "shi wan" instead of "yi shi wan", "2000 " read as "er qian" instead of "liang qian".

Input Format

There is a string of numbers, the numerical size of not more than 2,000,000,000.

Output Format

Is a string of lower case letters, spaces and commas composition, it represents the number of English reading.

Sample input

1234567009

Sample Output

shi er yi san qian si bai wu shi liu wan qi qian ling jiu

algorithm

After know about reading method can be written, so you need to keep an array of digital reading method, a memory array unit readings, there is no need bits, the empty positions on the line, because we usually do not read a bit. Then determine the size of the input to one hundred million yet? If the million (reciprocal ninth) the array will be aligned and one hundred million units, and locations “yi”, to Wan (fifth from the bottom position) is aligned with Wan, position “wan”, or align the last one, a position empty. E.g

12 3456 7890

10

​ 3210

​ 3210

Representative units of the second array row index thirty-four, the standard case is aligned million locations “yi”, and a reading unit to read a digital read out "yi shi er yi". Note that the position "yi", it is read out "yi". This number can be read out here, but still there are some problems, for example, 12 (only the beginning, or 1 in 412 to read) should be read as "shi er" instead of "yi shi er", the issue is good solution, plus a judge's conditions, beginning with 1 unit is "shi" when not read yi ".102 should be read as" yi bai ling er "instead of" yi bai ling shi er ", this problem is solved zero when the number and the unit is not reading, if you encounter on a number of non-zero digit is zero on to read a "ling".

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main(){	
	char s[11];
	cin>>s;
	string shu[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
	string d[6]={"","shi","bai","qian","wan","yi"};
	int len=strlen(s);
	int p;
	for(int i=0;i<strlen(s);i++)
	{
		if(strlen(s)-i>=9)
		p=9;
		else if(strlen(s)-i>=5)
		p=5;
		else
		p=1;
		int j=strlen(s)-p-i;
		if(s[i]!='0')
		{
			if(p==9) d[0]="yi ";
			else if(p==5) d[0]="wan ";
			else d[0]="";
			if(i>=1&&s[i-1]=='0') cout<<"ling"<<" ";
			if(!(i==0&&s[i]=='1'&&j==1))
			cout<<shu[s[i]-'0']<<" ";
			if(j!=0)
			cout<<d[j]<<" ";
			
		}
		if(j==0)
		{
			cout<<d[0];
			d[0]="";
		}
	}
}
Published 43 original articles · won praise 1 · views 916

Guess you like

Origin blog.csdn.net/qq_43985303/article/details/104865587