Comments (6)
我为什么觉得就应该读“yi Yi yi Qian er Bai san Shi si”呢……
from pat.
我不会改,要不你把正确代码发Pull Request给我?
from pat.
您好:
这个是我在维基百科上搜到的关于中文数字的读法的相关页面。
有如下:
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.
写的真好~已将代码更改为你的代码,感谢~
from pat.
...我也是看的别人的代码,女神都是凌晨就起床的么....
from pat.
嗯嗯,我休息的比较早~夏天这个点正好开始天亮,4点开始工作最合适啦
from pat.
Related Issues (20)
- 1018 不必模拟整个过程,need记录权重最小值即可
- [Advanced/C++/1135] Suggestion
- [Advanced/C++/1095] bug report
- [Advanced/C++/1159] Suggestion
- [Advanced/C++/1103]代码执行结果与样本输出结果不同,但是能够AC
- [Basic level Java] 1015 德才论
- [Basic level Java] 1017. A除以B (20) 全部运行超时
- PAT (Basic Level)1008 数组元素循环右移问题 更为简单做法
- 【改写原解法】PAT【甲级】1060 Are They Equal (25 分)
- 【甲级1014另解】1014 Waiting in Line
- PAT BasicLevel 1032
- Lanqiao
- 乙级1056 组合数的和(C++)更优解
- [Advence/c++/1026]测试样例改变,导致第一个测试点过不去
- 提供乙级1008 python版本的PythonIC风格代码
- Pat乙级1008 数组元素循环右移问题(简洁到极致的写法)
- PAT-B 1018. 锤子剪刀布 (20)(最简洁巧妙的写法)
- PAT甲级1025 学生id定义 HOT 1
- 【PAT Advanced Level 1026 Table Tennis】关于同一秒钟多个桌子空闲,分配多个客人的情况
- 1069答案只能得十分呀怎么办 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pat.