当前位置 : 主页 > 编程语言 > c++ >

2019.10.12 班级练习赛

来源:互联网 收集:自由互联 发布时间:2021-06-23
https://www.luogu.org/problem/T103143 https://www.luogu.org/problem/T103188 https://www.luogu.org/problem/T103328 c++版 Max And Min 1 #include stdio.h 2 #include math.h 3 #include algorithm 4 5 using namespace std; 6 7 int main() 8 { 9 int

https://www.luogu.org/problem/T103143

https://www.luogu.org/problem/T103188

https://www.luogu.org/problem/T103328

c++版

Max And Min

 1 #include <stdio.h>
 2 #include <math.h>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int a,b,c,d;
10     scanf("%d%d%d%d",&a,&b,&c,&d);
11     int ma; ma=max(max(max(a,b),c),d);
12     int mi; mi=min(min(min(a,b),c),d);
13     printf("%d\n%d\n",ma,mi);
14     return 0;
15 }

解方程

 1 #include<iostream>
 2 #include<cmath>
 3 #include<iomanip>
 4 
 5 using namespace std;
 6 
 7 double pd(double a,double b,double c)
 8 {
 9     double m=b*b-4*a*c;
10     return m;
11 }
12 
13 int main()
14 {
15     double a,b,c;
16     cin>>a>>b>>c;
17     if(a==0)
18     {
19         cout<<1<<endl<<fixed<<setprecision(4)<<-(c/b)<<endl;
20     }
21     else 
22     {
23         double disc=pd(a,b,c);
24         if(disc<0) cout<<"N0"<<endl;
25         else 
26         {
27             double x=(-b+sqrt(disc))/(2*a);
28             double xx=(-b-sqrt(disc))/(2*a);
29             double X=max(xx,x),Y=min(xx,x);
30             if(xx==x) cout<<1<<endl<<fixed<<setprecision(4)<<X<<endl;
31             else cout<<2<<endl<<fixed<<setprecision(4)<<Y<<" "<<X<<endl;
32         }
33     }
34     return 0;
35 }

进制数:

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 int n,m;
 6 
 7 int main()
 8 {
 9     cin>>n>>m;
10     int sum=0;
11     while(n)
12     {
13         sum+=n%m;
14         n/=m;
15     }
16     cout<<sum<<endl;
17 }

 

c版

min and max

 1 #include <stdio.h>
 2 
 3 int max(int x,int y)
 4 {
 5     if(x<y) return y;
 6     return x;
 7 }
 8 
 9 int min(int x,int y)
10 {
11     if(x>y) return y;
12     return x;
13 }
14 
15 int main()
16 {
17     int a,b,c,d;
18     scanf("%d%d%d%d",&a,&b,&c,&d);
19     int ma; ma=max(max(max(a,b),c),d);
20     int mi; mi=min(min(min(a,b),c),d);
21     printf("%d\n%d\n",ma,mi);
22     return 0;
23 }

 

解方程

 1 #include<stdio.h>
 2 #include<cmath>
 3 
 4 double max(double x,double y)
 5 {
 6     if(x<y) return y;
 7     return x;
 8 }
 9 
10 double min(double x,double y)
11 {
12     if(x>y) return y;
13     return x;
14 }
15 
16 double pd(double a,double b,double c)
17 {
18     double m=b*b-4*a*c;
19     return m;
20 }
21 
22 int main()
23 {
24     double a,b,c;
25     scanf("%lf%lf%lf",&a,&b,&c);
26     if(a==0)
27     {
28         printf("1\n%.4lf\n",-(c/b));
29     }
30     else 
31     {
32         double disc=pd(a,b,c);
33         if(disc<0) printf("%N0\n");
34         else 
35         {
36             double x=(-b+sqrt(disc))/(2*a);
37             double xx=(-b-sqrt(disc))/(2*a);
38             double X=max(xx,x),Y=min(xx,x);
39             if(xx==x) printf("1\n%.4lf",X);
40             else printf("2\n%.4lf %.4lf",Y,X);
41         }
42     }
43     return 0;
44 }

 

进制数:

 1 #include<stdio.h>
 2 
 3 int n,m;
 4 
 5 int main()
 6 {
 7     scanf("%d%d",&n,&m);
 8     int sum=0;
 9     while(n)
10     {
11         sum+=n%m;
12         n/=m;
13     }
14     printf("%d\n",sum);
15     return 0;
16 }
网友评论