当前位置:网站首页>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 .
边栏推荐
- Basis of information entropy
- The difference between tail -f, tail -f and tail
- Mathematical knowledge: step Nim game game game theory
- Androd gradle's substitution of its use module dependency
- 2022 Jiangxi Provincial Safety Officer B certificate reexamination examination and Jiangxi Provincial Safety Officer B certificate simulation examination question bank
- 传输层 TCP主要特点和TCP连接
- tail -f 、tail -F、tailf的区别
- C#应用程序界面开发基础——窗体控制(3)——文件类控件
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- 如今少年已归来,人间烟火气最抚凡人心 复工了~
猜你喜欢

【數據挖掘】任務6:DBSCAN聚類

看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9

C application interface development foundation - form control (1) - form form

Niu Ke swipes questions and clocks in

【数据挖掘】任务2:医学数据库MIMIC-III数据处理

【C语言】指针与数组笔试题详解

Androd Gradle 对其使用模块依赖的替换

Learn the five skills you need to master in cloud computing application development

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

A simple tool for analyzing fgui dependencies
随机推荐
A simple tool for analyzing fgui dependencies
如今少年已归来,人间烟火气最抚凡人心 复工了~
Qtablewidget lazy load remaining memory, no card!
C#应用程序界面开发基础——窗体控制(4)——选择类控件
【第29天】给定一个整数,请你求出它的因子数
The difference between tail -f, tail -f and tail
Why is it not recommended to use BeanUtils in production?
d. LDC build shared library
[QT] encapsulation of custom controls
C#应用程序界面开发基础——窗体控制(2)——MDI窗体
The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
C language course information management system
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
【我的OpenGL学习进阶之旅】关于欧拉角、旋转顺序、旋转矩阵、四元数等知识的整理
电信客户流失预测挑战赛
一比特苦逼程序員的找工作經曆
Tp6 fast installation uses mongodb to add, delete, modify and check
Why can't the start method be called repeatedly? But the run method can?
Detailed explanation of Q-learning examples of reinforcement learning
给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。【剑指Offer】