B2001 入门题测试(注意范围即可):

#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main(){
cin>>a>>b;
cout<<a+b;
return 0;
}

B2002 Hello,World!

#include<bits/stdc++.h>
using namespace std;
int main(){
     cout<<"Hello World!"
     return 0;
}

B2003 输出第二个整数

#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
cin>>a>>b>>c;
cout<<b;
}

B2053 求一元二次方程

#include<bits/stdc++.h>

using namespace std;

int main() {
double a, b, c;
cin >> a >> b >> c;
// Calculate discriminant
double discriminant = b * b - 4 * a * c;

// Check if there are real roots
if (discriminant < 0) {
cout << "No answer!" << endl;
} else if (discriminant == 0) {
double x1 = -b / (2 * a);
cout << fixed << setprecision(5) << "x1=x2=" << x1 << endl;
} else {
double sqrt_discriminant = sqrt(discriminant);
double x1 = (-b + sqrt_discriminant) / (2 * a);
double x2 = (-b - sqrt_discriminant) / (2 * a);

// Output roots in ascending order
if (x1 > x2) {
swap(x1, x2);
}

cout << fixed << setprecision(5) << "x1=" << x1 << ";x2=" << x2 << endl;

}

return 0;
}

0 条评论

目前还没有评论...