当前位置:网站首页>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

原网站

版权声明
本文为[hunziHang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140622508989.html