当前位置:网站首页>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
边栏推荐
- Transport connection management of TCP
- Haut OJ 1243: simple mathematical problems
- C语言杂谈1
- [paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
- Haut OJ 1350: choice sends candy
- 嵌入式数据库开发编程(六)——C API
- Shell Sort
- The present is a gift from heaven -- a film review of the journey of the soul
- cocos2dx_ Lua card flip
- 利用HashMap实现简单缓存
猜你喜欢
Web APIs DOM节点
On-off and on-off of quality system construction
2022年上半年国家教师资格证考试
Data is stored in the form of table
[turn]: OSGi specification in simple terms
Use of snippets in vscode (code template)
[to be continued] [UE4 notes] L1 create and configure items
Merge sort
[转]: OSGI规范 深入浅出
Collapse of adjacent vertical outer margins
随机推荐
小程序直播+電商,想做新零售電商就用它吧!
Three dimensional dice realize 3D cool rotation effect (with complete source code) (with animation code)
Yolov5 ajouter un mécanisme d'attention
2022/7/2 question summary
[turn to] MySQL operation practice (III): table connection
A complete attack chain
Haut OJ 1241: League activities of class XXX
Lua wechat avatar URL
Heap sort summary
嵌入式数据库开发编程(五)——DQL
[allocation problem] 455 Distribute cookies
嵌入式数据库开发编程(零)
Transport connection management of TCP
Service fusing hystrix
2022年上半年国家教师资格证考试
2022/7/1學習總結
Haut OJ 1245: large factorial of CDs --- high precision factorial
A three-dimensional button
Cocos progress bar progresstimer
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8