当前位置:网站首页>Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
Zheng Qing 21 ACM is fun. (3) part of the problem solution and summary
2022-07-05 05:20:00 【hunziHang】
1. problem C: an isosceles triangle ( Main pit points : Data range )
Problem description :
While wiping the table , One of the volunteers found some tables shaking , Smart volunteers immediately thought of the principle that triangles have stability . To form a triangle , Volunteers found three sticks , The lengths are a,b,c. Now smart, can you tell us that these three sticks can form an isosceles triangle ?
Input :
Multiple sets of test data
Enter three positive integers a、b and c, Each represents three sides of the triangle (a,b,c Both in int Within the scope of ).
Output :
If it is isosceles triangle output "Yes", Otherwise output "No".
The sample input :
1 2 2
Sample output :
Yes
Cause analysis :
1. Although the title said (a,b,c Both in int Within the scope of ), But when finding the sum of two sides , May exceed int Data range , therefore int Change it to long long That's all right. .
2. Only one example is given , You will mistakenly think that there are not multiple instances , But the title says multi instance input , So pay attention to the examination .
Solution :
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long a,b,c;
scanf("%lld%lld%%lld",&a,&b,&c)
if(a+b>c&&a+c>b&&b+c>a)
{
if(a==b||a==c||b=c)
printf("Yes\n");
else
printf("No\n");
}
else
printf("No\n");
}
}
2. problem E: Print graphics
Problem description :
According to the input capital English letters , Print graphics in the following form . for example , Input G
A AB ABC ABCD ABCDE ABCDEF ABCDEFG
Input :
Enter a capital letter
Output :
Output the right triangle described by the topic
The sample input :
E
Sample output :
A AB ABC ABCD ABCDE
Cause analysis :
The main point of this question is How to use the input capital letters to become Numbers , Thus the problem of how many lines to print is solved .
namely utilize n=x-'A'+1; Create an array , keep for the future 26 Letters
Solution :
#include<stdio.h>
int main()
{
int i,j,k,n;
char a[30]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'},x;
scanf("%c",&x);
n=x-'A'+1;
for(i=1;i<=n;i++)
{
for(j=n-i;j>0;j--)
printf(" ");
for(k=0;k<i;k++)
printf("%c",a[k]);
printf("\n");
}
return 0;
}
3. problem I: Preparation before the game -- shift
Problem description :
After a long time of labor . The volunteers are exhausted ( I really appreciate them ), But there are still many tasks . So the volunteers came up with a way , Use three numbers to decide who will do the next task , So that others can rest .
The rule is : Three numbers n、m and k, Everyone chooses one 0-9 The number of , according to n/m Of the k Decimals to determine who will come to the next task , If n/m Of the k The number of decimal places is s, So choose s The numbered people rest . Xiao Ming is too tired , So ask how you can get the answer quickly .
Input :
Multiple sets of test data .
Each set of test data input has three positive integers n,m,k.(1<=n, m<=1000, 1<=k<=100000)
Output :
Output n/m Of the k Numbers in decimal places .
The sample input :
1 2 3 1 3 3
Sample output :
0 3
Cause analysis :
High precision problem , Directly according to the mathematical method Simulation is enough
1. int n1=n%m; for instance 10/3 Then it must be the remainder to operate , So first take the remainder .
2. m1=(n1*10)/m; m1 That is, the decimal part because 10/3 more than 1 The next step should be math 10/3 therefore n1*10. also /
3. Update the remainder n1=(n1*10)%m;
Solution :
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n,m,k;
while(scanf("%d%d%d",&n,&m,&k)!=EOF){
int n1=n%m;
int m1=0;
int sum1=0;
while(sum1<k){
m1=(n1*10)/m;
n1=(n1*10)%m;
sum1++;
}
printf("%d\n",m1);
}
return 0;
}
summary :
1. When doing questions Seriously Fast Reading questions , Sift out secondary information .
2.int You can all Defined as long long avoid Out of data range
3. Come on, understand and train characters
边栏推荐
- Listview pull-down loading function
- [turn]: Apache Felix framework configuration properties
- 软件测试 -- 0 序
- Embedded database development programming (VI) -- C API
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- 嵌入式数据库开发编程(零)
- [merge array] 88 merge two ordered arrays
- 一个新的微型ORM开源框架
- Generate filled text and pictures
- 使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
猜你喜欢
2022年上半年国家教师资格证考试
Yolov5 ajouter un mécanisme d'attention
Optimization scheme of win10 virtual machine cluster
C语言杂谈1
Download and use of font icons
Stm32cubemx (8): RTC and RTC wake-up interrupt
Bucket sort
Binary search basis
Use of snippets in vscode (code template)
Django reports an error when connecting to the database. What is the reason
随机推荐
Stm32cubemx (8): RTC and RTC wake-up interrupt
Romance of programmers on Valentine's Day
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
2022/7/1學習總結
[sum of two numbers] 169 sum of two numbers II - enter an ordered array
Unity ugui source code graphic
Grail layout and double wing layout
Page countdown
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
[turn to] MySQL operation practice (I): Keywords & functions
Pointnet++的改进
object serialization
To be continued] [UE4 notes] L4 object editing
How can the Solon framework easily obtain the response time of each request?
Bucket sort
xftp7与xshell7下载(官网)
Download xftp7 and xshell7 (official website)
质量体系建设之路的分分合合
Solon 框架如何方便获取每个请求的响应时间?
Cocos create Jiugongge pictures