当前位置:网站首页>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 .
边栏推荐
- Machine learning terminology
- 【第29天】给定一个整数,请你求出它的因子数
- Type expansion of non ts/js file modules
- [understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait
- Basis of information entropy
- SSL flood attack of DDoS attack
- [interview question] 1369 when can't I use arrow function?
- Openresty cache
- What operations need attention in the spot gold investment market?
- The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
猜你喜欢

wirehark数据分析与取证A.pacapng

Wireshark data analysis and forensics a.pacapng
![[data mining] task 5: k-means/dbscan clustering: double square](/img/e7/678197e703d1a28b765a0e3afd5580.png)
[data mining] task 5: k-means/dbscan clustering: double square

High resolution network (Part 1): Principle Analysis

Tâche 6: regroupement DBSCAN

Learn the five skills you need to master in cloud computing application development
![[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio](/img/70/54eb9359ac91aa43383b240eb036b7.gif)
[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio

Basis of information entropy

A simple tool for analyzing fgui dependencies

Machine learning terminology
随机推荐
Leetcode 6103 - minimum fraction to delete an edge from the tree
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
MySQL - database query - basic query
Common English Vocabulary
What operations need attention in the spot gold investment market?
数学知识:Nim游戏—博弈论
High resolution network (Part 1): Principle Analysis
Leetcode 2097 - Legal rearrangement of pairs
Look at how clothing enterprises take advantage of the epidemic
MySQL --- 数据库查询 - 条件查询
【数据挖掘】任务6:DBSCAN聚类
不登陆或者登录解决oracle数据库账号被锁定。
Work experience of a hard pressed programmer
[FPGA tutorial case 6] design and implementation of dual port RAM based on vivado core
Is there anything in common between spot gold and spot silver
【数据挖掘】任务2:医学数据库MIMIC-III数据处理
wirehark数据分析与取证A.pacapng
【面试题】1369- 什么时候不能使用箭头函数?
Introduction to flask tutorial
[system analyst's road] Chapter V double disk software engineering (development model development method)