当前位置:网站首页>[Niuke brush questions] / * daily four programming questions to share*/
[Niuke brush questions] / * daily four programming questions to share*/
2022-07-20 06:19:00 【Ling Chenqi】
hi ! Welcome to Ling Chenqi's blog homepage !
Series column :【 Niuke brush question recording station 】 Welcome to subscribe to !
Here is C Some knowledge of language learning , If you come in, please aim at the knowledge points !
Author's brief introduction : A sophomore who is going to be promoted to a junior in the major class Xiaobai , I'm ordinary , But learn to work hard !
My code is stored in the warehouse :️️https://gitee.com/king-zhou-of-java/java-road.git Welcome to your attention !
Catalog
One 、 Sum the greatest common divisor and the least common multiple
Four 、 Civil service interview
One 、 Sum the greatest common divisor and the least common multiple
Problem description :
Xiao Lele recently learned in class how to find the maximum common divisor and minimum common multiple of two positive integers , But he can't find the sum of the maximum common divisor and the minimum common multiple of two positive integers , Please help him solve the problem .
Input description :
Each set of inputs contains two positive integers n and m.(1 ≤ n ≤ 109,1 ≤ m ≤ 109) Output description
Output description :
For each group of input , Output a positive integer , by n and m The sum of the greatest common divisor and the least common multiple of .
Example :
Input :
10 20
Output :
30
* Problem analysis :
What we need to know here is the least common multiple =(m*n)/ greatest common divisor ;
Code implementation :
#include<stdio.h>
int main()
{
long long m;
long long n;
scanf("%d %d",&m,&n);
long long p= m*n;
while(n!=0)
{
long long t=m%n;
m=n;
n=t;
}
long long max=m;
long long min=p/m;
printf("%lld",max+min);
}
Two 、 Hollow square pattern
Problem description :
KiKi I learned the cycle ,BoBo The teacher gave him a series of printing exercises , The task is to print “*” Composed of “ Hollow ” Square pattern .
Input description :
Multi group input , An integer (3~20), Represents the number of rows output , It also means that the sides of a square are made up of “*” The number of .
Output description :
Enter... For each line , For output “*” Composed of “ Hollow ” Square , Every “*” There is a space after .
Example :
Input :
4
Output :
* * * * * * * * * * * *
️️ Problem analysis :
We can see that this question uses * Output a square surrounded by * And the middle is a pattern of spaces , Then we can define a two-dimensional array , Then print by cycling , Control judgment conditions , Assign a value of * still " ".
Code implementation :
#include<stdio.h>
void print(int a)
{
int i,j;
for(i=0;i<a;i++)
{
for(j=0;j<a;j++)
{
if(i==0 || i==a-1 || j == 0 || j == a-1)
{
printf("* ");
}
else
printf(" ");
}
printf("\n");
}
}
int main()
{
int a=0;
while(scanf("%d",&a)!=EOF)
{
print(a);
}
return 0;
}
Running results :
3、 ... and 、 Arrow pattern
Input description :
Multiple groups of input , One integer per row (2~20).
Output description :
Enter... For each line , For output “*” The shape of an arrow .
Example 1:
Input :
2
Output :
* ** *** ** *
Example 2:
Input :
3
Output :
* ** *** **** *** ** *
Problem analysis :
We also need to find the right method for this problem , We can find that this is a symmetrical figure up and down , So we can try to print the graphics on the top half first , Then print the graphics on the bottom half in the same way , utilize for Cycle control printing , See code comments for specific public functions .
Code implementation :
#include <stdio.h>
int main()
{
int a;
while(scanf("%d",&a)!=EOF)// Meet the cycle requirements
{
for(int i=1;i<=a+1;i++)// According to the requirements of the topic, first show the upper half of the arrow
{
for(int j=1;j<=(a+1-i)*2+i;j++)// Combine loops and judgments to determine spaces and * The number of
{
if(j<=(a+1-i)*2)
{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");// Pay attention to the position of line breaks ;
}
for(int m=1;m<=a;m++)// Show the lower half of the arrow in the same way
{
for(int n=1;n<=m*2+a+1-m;n++)
{
if(n<=(m*2))
{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");
}
}
return 0;
}
Running results :
Four 、 Civil service interview
Problem description :
Civil servant interview on-site scoring . Yes 7 Examiner , Enter several groups of grades from the keyboard , Each group 7 A score ( Percentage system ), Take out the highest score and the lowest score , Output the average score of each group .
( notes : There are many groups of input )
Input description :
Every line , Input 7 It's an integer (0~100), representative 7 Achievements , Separate... With spaces .
Output description :
Every line , Output the average score excluding the highest and lowest scores , After the decimal point 2 position , Wrap after output of each line .
Example 1:
Input :
99 45 78 67 72 88 60
Output :
73.00
️️ Problem analysis :
This question is relatively simple , We design sort The function first finds out the highest score and the lowest score , Then calculate the seven scores and subtract the highest and lowest scores , Finally, find the average value , Pay attention to our count = 0; max = 0;small = 100; sum = 0; These four parts need to be reset to the initial value after our judgment !🧂🧂
Code implementation :
#include <stdio.h>
int main()
{
int a, max = 0, small = 100, sum = 0, count = 0;
while (scanf("%d", &a) != EOF)
{
if (a > max)// Determine the highest score
{
max = a;
}
if (a < small)// Determine the lowest score
{
small = a;
}
sum += a;
count++;// Counter
if (count == 7)// Counter =7 When the score represents a group, it can be calculated
{
printf("%.2f\n", (sum - max - small) / 5.0);
count = 0;// Reset
max = 0;// Reset
small = 100;// Reset
sum = 0;// Reset
}
}
return 0;
}
Running results :
Okay , That's all for today's problem analysis , Thank you for reading !
边栏推荐
- 【测量学】水准测量
- Various operations of selenium
- Optional empty judgment operation
- DeFi 2.0的LaaS协议Elephant,重振DeFi赛道发展的关键
- Is it safe for Guangzhou GF Securities to open an account? How much is the handling charge
- ClickHouse跨集群表数据同步
- J9数字货币平台科普:Sui网络的双共识是如何工作的?
- 【C 练习】公务员面试
- Based on yarn1 Sharing of monorepo practice of X
- Introduction and use of finalshell
猜你喜欢
LeetCode-补充题6-手撕堆排序
(二)fastai 2019 part2 重点提炼
J9 digital currency platform popular science: how does the double consensus of Sui network work?
【C 练习】公务员面试
FAST-LIO2代码解析(一)
Sleepless nights in summer
Shell 基本命令操作(seq-序列、tr-转换)
【Jailhouse 文章】Specific Electronic Platform to Test the Influence of Hypervisors on the Performance..
Shell query Prometheus data
解压文件遇到:gzip: stdin: invalid compressed data--format violated
随机推荐
洛谷P1016 [NOIP1999 提高组] 旅行家的预算 题解
Qianshi application | SRT Internet transmission technology program successfully assisted the "Jiangxi emergency · 2022" comprehensive drill
Ali test engineer's words will save you ten years of detours
金融银行软件测试超大型攻略,最受欢迎的金融银行大揭 秘附面试题
【Jailhouse 文章】Specific Electronic Platform to Test the Influence of Hypervisors on the Performance..
【微信小程序】常用组件及基本使用详解
7. [WebGIS practice] special topic - API key
[Development Tutorial 4] crazy shell arm function mobile phone - development interface connection tutorial
广州广发证券开户安全吗,手续费多少
Set up [redis cluster in centos7. X]
路由器和交换机的区别
[intelligent hardware] notes on Jetson nano problems
搭建【Redis-Cluster in CentOS7.x】
夏日不眠夜
Specify the installation source of PIP install
(二)fastai 2019 part2 重点提炼
买股票哪个证券公司最好?哪个券商平台最安全
Which securities company is the best to buy stocks? Which brokerage platform is the safest
树莓派 3B 更换 4.9.80 内核(64bit)
Selected questions: force deduction 565 Array nesting