ZZULIOJ 1011~1015 (c++)

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);

}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值