1011: 圆柱体表面积
#include <iomanip>
using namespace std;
#define PI 3.14159
int main(){
double r;
double h;
cin>>r>>h;
double l = 2*PI*r*h;
double y = PI*r*r;
//cout<<l<<" "<<y<<endl;
cout<<setiosflags(ios::fixed)<<setprecision(2)<<l + y*2;
// cout<<setiosflags(ios::fixed)<<setprecision(2)<<r*PI*r;
}
1012: 求绝对值
#include<iostream>
#include <iomanip>
using namespace std;
#define PI 3.14159
int main(){
double n;
cin>>n;
if(n>=0){
cout<<setiosflags(ios::fixed)<<setprecision(2)<<n;
}else{
cout<<setiosflags(ios::fixed)<<setprecision(2)<<0-n;
}
}
#include<iostream>
#include <iomanip>
using namespace std;
#define PI 3.14159
int main(){
double n;
cin>>n;
if(n>=0){
cout<<setiosflags(ios::fixed)<<setprecision(2)<<n;
}else{
cout<<setiosflags(ios::fixed)<<setprecision(2)<<0-n;
}
}
1013: 求两点间距离
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
int main(){
double x1,y1;
double x2,y2;
cin>>x1>>y1>>x2>>y2;
double x;
double y ;
if(x1>x2){
x = x1-x2;
}else{
x = x2-x1;
}
if(y1>y2){
y = y1-y2;
}else{
y = y2-y1;
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<< sqrt(x*x+y*y);
// cout<<setiosflags(ios::fixed)<<setprecision(2)<<r*PI*r;
}
1014: 求三角形的面积
海伦公式
#include<iostream>
#include <iomanip>
#include<math.h>
using namespace std;
int main(){
double a,b,c;
cin>>a>>b>>c;
double p =(a+b+c)/2;
cout<<setiosflags(ios::fixed)<<setprecision(2)<< sqrt(p*(p-a)*(p-b)*(p-c));
// cout<<setiosflags(ios::fixed)<<setprecision(2)<<r*PI*r;
}
1015: 计算时间间隔
不知道为何这道题c++的代码不能通过
附上我没有通过的c++代码(本人觉得没有错误)
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int t1[3] = {0};
int t2[3] = {0};
int j=0;
string s1;
string s2;
cin>>s1>>s2;
char c1[s1.length()];
char c2[s2.length()];
strcpy(c1,s1.data());
strcpy(c2,s2.data());
for(int i =0;i<s1.length();i=i+3){
t1[j] = (c1[i]-'0') *10 + (c1[i+1]-'0');
t2[j] = (c2[i]-'0') *10 + (c2[i+1]-'0');
j++;
}
int time = 0;
if(t2[2]>=t1[2]){
time = time + t2[2]-t1[2];
}else{
t2[1]--;
time = time +t2[2]+60-t1[2];
}
if(t2[1]>=t1[1]){
time = time + (t2[1]-t1[1])*60;
}else{
t2[0]--;
time = time + (t2[2]+60-t1[2])*60;
}
if(t2[0]>=t1[0]){
time = time + (t2[0]-t1[0])*3600;
}
cout<<time;
}
毕竟复试机试要用c语言,要开始用c了~
c语言这个是通过了测试的
int main(){
int h1,m1,s1;
int h2,m2,s2;
scanf("%d:%d:%d",&h1,&m1,&s1);
scanf("%d:%d:%d",&h2,&m2,&s2);
int time = 0;
if(s2>=s1){
time = time +s2-s1;
}else{
m2--;
time = time+s2+60-s1;
}
if(m2>=m1){
time = time + (m2-m1)*60;
}else{
h2--;
time = time+ (m2+60-m1)*60;
}
if(h2>=h1){
time = time +(h2-h1)*3600;
}
printf("%d",time);
}