当前位置:网站首页>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 .
边栏推荐
- [机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
- 传输层 TCP主要特点和TCP连接
- Vim 9.0正式发布!新版脚本执行速度最高提升100倍
- 产业互联网的产业范畴足够大 消费互联网时代仅是一个局限在互联网行业的存在
- 【第29天】给定一个整数,请你求出它的因子数
- Tp6 fast installation uses mongodb to add, delete, modify and check
- uniapp组件-uni-notice-bar通告栏
- 一位苦逼程序员的找工作经历
- Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
- d. LDC build shared library
猜你喜欢

Basic concept and implementation of overcoming hash
![[fh-gfsk] fh-gfsk signal analysis and blind demodulation research](/img/8a/8ca80f51a03341c982d52980c54b01.png)
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research

强化学习 Q-learning 实例详解

Database SQL language 02 connection query
![[interview question] 1369 when can't I use arrow function?](/img/7f/84bba39965b4116f20b1cf8211f70a.png)
[interview question] 1369 when can't I use arrow function?

MySQL foundation 04 MySQL architecture

Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm

什么是调。调的故事

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr

【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
随机推荐
[技术发展-23]:DSP在未来融合网络中的应用
[self management] time, energy and habit management
2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
Arduino DY-SV17F自动语音播报
Is there a handling charge for spot gold investment
Is there anything in common between spot gold and spot silver
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
MySQL - database query - condition query
[Cao gongzatan] after working in goose factory for a year in 2021, some of my insights
SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
[interview question] 1369 when can't I use arrow function?
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
电信客户流失预测挑战赛
leetcode 2097 — 合法重新排列数对
Androd Gradle 对其使用模块依赖的替换
JDBC courses
Learn the five skills you need to master in cloud computing application development
How is the mask effect achieved in the LPL ban/pick selection stage?
Canvas drawing -- bingdd