当前位置:网站首页>7-25 read numbers (loop switch)
7-25 read numbers (loop switch)
2022-07-03 01:35:00 【Big fish】
Enter an integer , Output the Pinyin corresponding to each number . When the integer is negative , First, the output fu
word . The Pinyin corresponding to ten numbers is as follows :
0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu
Input format :
Input gives an integer on a line , Such as :1234.
Tips : Integers include negative numbers 、 Zero and positive .
Output format :
Output the Pinyin corresponding to the integer in one line , The Pinyin of each number is separated by a space , There is no final space at the end of the line . Such as yi er san si.
sample input :
-600
No blank lines at the end
sample output :
fu liu ling ling
No blank lines at the end
There are two ways to achieve this :
Code 1:
#include<stdio.h>
int main()
{
int num = 0;
int a[11] = { 0 };
scanf("%d", &num);
if (num < 0)
{
printf("fu ");
num *= -1;
}
if (num == 0)
{
printf("ling");
}
int k = 0,i=0;
while (num)// Store each bit of data in the array .
{
a[i] = num % 10;
i++;
num /= 10;
}
k = --i;
for(int i=k;i>=0;i--)// Print each bit in turn , Last, don't print spaces
{
switch (a[i])
{
case 0:
if (i == 0)
{
printf("ling");
break;
}
printf("ling ");
break;
case 1:
if (i == 0)
{
printf("yi");
break;
}
printf("yi ");
break;
case 2:
if (i == 0)
{
printf("er");
break;
}
printf("er ");
break;
case 3:
if (i == 0)
{
printf("san");
break;
}
printf("san ");
break;
case 4:
if (i == 0)
{
printf("si");
break;
}
printf("si ");
break;
case 5:
if (i == 0)
{
printf("wu");
break;
}
printf("wu ");
break;
case 6:
if (i == 0)
{
printf("liu");
break;
}
printf("liu ");
break;
case 7:
if (i == 0)
{
printf("qi");
break;
}
printf("qi ");
break;
case 8:
if (i == 0)
{
printf("ba");
break;
}
printf("ba ");
break;
case 9:
if (i == 0)
{
printf("jiu");
break;
}
printf("jiu ");
break;
}
}
return 0;
}
result :
test result :
Code 2:
#include<stdio.h>
int main()
{
int num = 0;
scanf("%d", &num);
if (num < 0)
{
printf("fu ");
num *= -1;
}
if (num == 0)
printf("ling");
int t = num;
int i = 1;
while (num)// This part is about num Figure out the number of digits
{
i *= 10;
num /= 10;
}
i = i / 10;
int m = 0,d=0;
while(i)// Print directly from the top
{
m = t / i;
d = m % 10;
i /= 10;
switch (d)
{
case 0:
if (i == 0)
{
printf("ling");
break;
}
printf("ling "); break;
case 1:
if (i == 0)
{
printf("yi");
break;
}
printf("yi "); break;
case 2:
if (i == 0)
{
printf("er");
break;
}
printf("er "); break;
case 3:
if (i == 0)
{
printf("san");
break;
}
printf("san "); break;
case 4:
if (i == 0)
{
printf("si");
break;
}
printf("si "); break;
case 5:
if (i == 0)
{
printf("wu");
break;
}
printf("wu "); break;
case 6:
if (i == 0)
{
printf("liu");
break;
}
printf("liu "); break;
case 7:
if (i == 0)
{
printf("qi");
break;
}
printf("qi "); break;
case 8:
if (i == 0)
{
printf("ba");
break;
}
printf("ba "); break;
case 9:
if (i == 0)
{
printf("jiu");
break;
}
printf("jiu "); break;
}
}
return 0;
}
test result :
The problem itself is not difficult , It's easy to grasp the printing order of this problem , In fact, I have learned data structure , Stack to achieve the best .
边栏推荐
- Create your first Kivy program Hello word (tutorial includes source code)
- Mathematical knowledge: Nim game game theory
- 一比特苦逼程序員的找工作經曆
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- openresty 缓存
- 测试右移:线上质量监控 ELK 实战
- Mathematical knowledge: step Nim game game game theory
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- Uniapp component -uni notice bar notice bar
- [Androd] Gradle 使用技巧之模块依赖替换
猜你喜欢
Force buckle 204 Count prime
Basis of information entropy
[data mining] task 6: DBSCAN clustering
什么是调。调的故事
传输层 TCP主要特点和TCP连接
Summary of interval knowledge
Telecom Customer Churn Prediction challenge
C#应用程序界面开发基础——窗体控制(2)——MDI窗体
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
Learn the five skills you need to master in cloud computing application development
随机推荐
The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
Niu Ke swipes questions and clocks in
QTableWidget懒加载剩内存,不卡!
JDBC courses
Openresty cache
Type expansion of non ts/js file modules
Force buckle 204 Count prime
电信客户流失预测挑战赛
Detailed explanation of Q-learning examples of reinforcement learning
C#应用程序界面开发基础——窗体控制(3)——文件类控件
C language course information management system
Meituan dynamic thread pool practice ideas, open source
C#应用程序界面开发基础——窗体控制(2)——MDI窗体
Mathematical knowledge: Nim game game theory
软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
MySQL foundation 04 MySQL architecture
Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
【數據挖掘】任務6:DBSCAN聚類
tail -f 、tail -F、tailf的区别
Arduino dy-sv17f automatic voice broadcast