团体程序设计天梯赛-L1-007 念数字

L1-007 念数字

在这里插入图片描述
解题思路
感觉跟PAT乙级-1002 写出这个数这道题挺像的,但是本题比这道题要简单,感兴趣的可以去看看我的博客传送门-1002 写出这个数

  • 输入时字符串输入
  • 用一个string数组将数字拼音与数组下标一 一对应,以便实现数字与拼音的转换
  • 符号单独判断即可

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
string s;
string a[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(i!=0)
			cout<<" ";
		if(s[i]=='-')
			cout<<"fu";
		else
			cout<<a[s[i]-'0'];
	}
	return 0;
}

发布了88 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Fiveneves/article/details/104623218