郑州轻工业oj1000~1049

1000: 从今天开始入坑C语言

ZZULIOJ

#include<iostream>
using namespace std;

int main(){
	
	cout<<"从今天开始入坑C语言";
	return 0;
} 

1001: 整数a+b

ZZULIOJ

#include<iostream>

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<a+b<<endl;
	return 0;
}

##1002: 简单多项式求值

ZZULIOJ

#include<iostream>
using namespace std;

int main(){
	int x;
	cin>>x;
	cout<<2*x*x+x+8;
	return 0;
}

1003: 两个整数的四则运算

ZZULIOJ

#include<iostream>

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<a+b<<" "<<a-b<<" "<<a*b<<" "<<a/b<<" "<<a%b<<endl;
	
}

1004: 三位数的数位分离

ZZULIOJ

#include<iostream>

using namespace std;

int main(){
	int x;
	cin>>x;
	cout<<x%10<<" "<<(x/10)%10<<" "<<x/100<<endl;
	 
	return 0;
}

1005: 整数幂

ZZULIOJ

pow()函数

#include<iostream>
#include<cmath>
using namespace std;

int main(){

int a,b,c;
cin>>a>>b>>c;

printf("%-9d%-9d%-9d\n",a,a*a,a*a*a);
printf("%-9d%-9d%-9d\n",b,b*b,b*b*b);
printf("%-9d%-9d%-9d\n",c,c*c,c*c*c);
	
}

1006: 求等差数列的和

ZZULIOJ

#include<iostream>

using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int sum = 0;
	for(int i = a;i<=b;i = i +c){
		sum+=i;
	}
	cout<<sum;
	return 0;
}

1007: 鸡兔同笼

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	//假设都是兔子  应该有a*4脚 ,但是只有b个脚,插值就是 鸡假冒兔子少的脚
	int x = 0,y =0;//x鸡  y兔
	x = (a*4 - b )/2;
	y =a - x;
	cout<<x<<" "<<y<<endl;
	return 0;
}

1008: 美元和人民币

ZZULIOJ

#include<iostream>
using namespace std;

int main(){
	double a;
	cin>>a;
	printf("%.2lf",a*6.5573);
}

1009: 求平均分

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	double a,b,c;
	cin>>a>>b>>c;
	printf("%.2lf",(a+b+c)/3);
	return 0;
} 

1010: 求圆的周长和面积

ZZULIOJ

#include<iostream>

const double PI = 3.14159;
using namespace std;
int main(){
	double r;
	cin>>r;
	printf("%.2lf %.2lf",2*PI*r,PI*r*r);
	return 0;
	
}

1011: 圆柱体表面积

ZZULIOJ

#include<iostream>
#define PI 3.14159
using namespace std;
int main(){
	double r,h;
	cin>>r>>h;
	printf("%.2lf",2*PI*r*r+2*r*PI*h);
	return 0;
}

1012: 求绝对值

ZZULIOJ

#include<iostream>

using namespace std;
int main(){
	double x;
	cin>>x;
	if(x<0){
		x = -x;
	}
	printf("%.2lf",x);
	return 0;
}

1013: 求两点间距离

ZZULIOJ

sqrt()函数

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double x1,y1,x2,y2;
	cin>>x1>>y1>>x2>>y2;
	printf("%.2lf",sqrt((x1-x2)*(x1-x2) +(y1-y2)*(y1-y2))); 
	return 0;
	
}

1014: 求三角形的面积

ZZULIOJ

任意三角形的面积公式(海伦公式):S^2=p(p-a)(p-b)(p-c), p=(a+b+c)/2, a,b,c为三角形三边。

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double a,b,c;
	cin>>a>>b>>c;
	double p = (a + b + c) /2;
	double s = sqrt(p*(p-a)*(p-b)*(p-c));
	printf("%.2lf",s);
	return 0;
}

1015: 计算时间间隔

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	char e;
	int res = 0; 
	cin>>a>>e>>b>>e>>c;
	res = a*3600+b*60+c;
	cin>>a>>e>>b>>e>>c;
	res = a*3600+b*60+c - res;
	cout<<res<<endl;
	return 0;

} 

1016: 银行利率

ZZULIOJ

#include<iostream>

using namespace std;

int main(){
	int n;
	double money;
	cin>>n>>money;

	while(n--)
	{
		money = money*(1+0.0225);
	}
	printf("%.6lf",money);
	return 0;
} 

1017: 判断正整数位数

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int res = 0;
	if(n< 10) res =1;
	else{
		while(n){
			n = n/10;
			res++;
		}
	}
	cout<<res<<endl;
	return 0;
}

1018: 奇数偶数

ZZULIOJ

#include<iostream>

using namespace std;

int main(){
	int a;
	cin>>a;
	if(a%2 ==0){
		cout<<"even"<<endl;
	}
	else{
		cout<<"odd";
	}
	return 0;
}

1019: 公园门票

#include<iostream>

using namespace std;
int main(){
	int n;
	cin>>n;
	int res = 0;	
	res = n*50;
	if(n >= 30){
		res =  n * (50-2);
	}
	cout<<res<<endl;
	return 0;
} 

1020: 两整数排序

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(b<a){
		cout<<b<<" "<<a;
	}
	else{
		cout<<a<<" "<<b;
	}
	return 0;
} 

1021: 三个整数的最大值

ZZULIOJ

#include<iostream>

using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	//将最大的数赋值给a
	if(b>a){
		swap(a,b);
	} 
	if(c>a){
		swap(a,c);
	}
	cout<<a;
	return 0;
	
}

1022: 三整数排序

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	//思路将最大的放在第一位
	if(b>a){
		swap(a,b);
	} 
	if(c>a){
		swap(a,c);
	}
	//此时a最大
	if(c>b){
		swap(b,c);
	} 
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

1023: 大小写转换

ZZULIOJ

A~Z 的ASCII 65~90 a~z 的ASCII 97~122

A->a ASCII值+32

英文大写字母AZ,小写字母az对应的ASCII码快速查询_ascall码对照表a到z-CSDN博客

#include<iostream>
using namespace std;
int main(){
	char c;
	cin>>c;
	if(c >= 65 && c <= 90) {
		c = c+32;
	} 
	if(c >=97 && c<=122){
		c = c -32;
	}
	cout<<c;
	return 0;
}

1024: 计算字母序号

ZZULIOJ

#include<iostream>

using namespace std;

int main(){
	char c;
	cin>>c;
	int idx =0;
	if(c>=65&&c<=90){
		idx = c - 'A' + 1;
	}
	if(c >=97 && c <= 122){
		idx = c - 'a' +1;
	}
	cout<<idx;
	return 0;
	
}

1025: 最大字符

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	char c1,c2,c3;
	cin>>c1>>c2>>c3;
	char temp;
	//最大放在c1;
	if(c2 > c1){
		temp = c2;
		c2 = c1;
		c1 =temp; 
	} 
	if(c3 > c1){
		temp = c3;
		c3 = c1;
		c1 = temp;
	}
	cout<<c1<<endl;
	return 0;
}

1026: 字符类型判断

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	
	char c;
	cin>>c;
	if(c >= 65 && c <= 90){
		cout<<"upper";
	}
	else if (c >= 97 && c <= 122){
		cout<<"lower";
	}
	else if(c >= '0' && c <= '9'){
		cout<<"digit";
	}
	else {
		cout<<"other";
	}
	return 0;
}

1027: 判断水仙花数

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int x;
	cin>>x;
	int a = x%10;
	int b = x/10%10; 
	int c = x/100%10;
	if(x == a*a*a+b*b*b+c*c*c){
		cout<<"yes"<<endl;
	} 
	else cout<<"no"<<endl;
	return 0;	
} 

1028: I love 闰年!

ZZULIOJ

闰年:

  • 能被4整除,但不能被100整除
  • 能被400整除
#include<iostream>

using namespace std;
int main(){
	int n;
	cin>>n;
	if((n%4==0 && n%100 != 0 )|| n % 400 == 0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

1029: 三角形判定

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a + b > c && a + c > b && b + c > a){
		cout<<"Yes";
	}
	else{
	cout<<"No";
	}
	return 0;
}

1030: 判断直角三角形

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	//abc中获取最大值赋值给a
	if(b > a) {
		swap(a,b);
	} 
	if(c > a){
		swap(a,c);
	}
	if(a*a == b*b + c*c){
		cout<<"yes";
	}
	else cout<<"no";
	return 0;
}

1031: 判断点在第几象限

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if(x>0){
		if(y>0) cout<<1;
		else cout<<4; 
	}
	else{
		if(y > 0) cout<<2;
		else cout<<3;
	}
	return 0;
}

1032: 员工薪水

ZZULIOJ

#include<iostream>

using namespace std;
int main(){
	double x;
	cin>>x;
	double money = 1500;
	double more = 0;
	if(x <= 10000){
		more = x * 0.05;
	}
	else if(x <=50000){
		more = 10000*0.05;
		more += (x - 10000)*0.03;
	}
	else{
		more = 10000*0.05;
		more += 40000*0.03;
		more += (x-50000)*0.02;

	}
	printf("%.2lf",money+more);
	return 0;
}

1033: 五级制成绩

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	if(a>= 90) cout<<"A";
	else if(a >= 80)cout<<"B";
	else if(a >=70) cout<<"C";
	else if(a >=60) cout<<"D";
	else cout<<"E";
	return 0;
	
} 

1034: 夏季促销

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	double x;
	cin>>x;
	if(x >=500 && x < 1000){
		x = x*0.95;
	}
	else if(x < 3000){
		x = x*0.9;
	}
	else if(x <5000){
		x = x*0.85;
	}
	else{
		x = x*0.8;
	}
	
	printf("%.2lf",x);
	return 0;
	
}

1035: 分段函数求值

ZZULIOJ

#include<iostream>

using namespace std;
int main(){
	int x;
	cin>>x;
	int y = 0;
	if(x < -2){
		y = 7 - 2*x;
	}
	if(x >= -2 && x < 3){
		if(3*x + 2 < 0){
			y = 5 +3*x +2;
		}
		else y = 5 - (3*x + 2);
	}
	if(x >= 3) y = 3 *x + 4;
	cout<<y;
	return 0; 
}

1036: 某年某月有多少天

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if((a%4==0 && a%100!=0 )|| a%400 ==0){
		if(b == 2){
			cout<<29;
		}
		else if(b==4||b==6||b== 9||b== 11){
			cout<<30;
		}
		else cout<<31;
		
	}
	
	else {
			if(b == 2){
			cout<<28;
		}
		else if(b==4||b==6||b== 9||b== 11){
			cout<<30;
		}
		else cout<<31;
		
	}
	return 0;
}

1037: 四则运算

ZZULIOJ

#include<iostream>
#include<cmath> 
using namespace std;
int main(){
	double a,b;
	char c;
	cin>>a>>c>>b;
	switch(c){
		case '+':
			printf("%.2lf",a+b);break;
			
		case '-' :
			printf("%.2lf",a-b);break;
			
		case '*':
			printf("%.2lf",a*b);break;
			
		case '/' :
			if(fabs(b) <= 1e-10){
				printf("Wrong input!");break;
			}
			else{
				printf("%.2lf",a/b);break;
			}
		default: printf("Wrong input!");
			
	}
	return 0;
}

1038: 绝对值最大

ZZULIOJ

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(fabs(b) > fabs(a)){
		swap(a,b);
	}
	if(fabs(c)>fabs(a)){
		swap(a,c);
	}
	cout<<a;
	return 0;
}

1039: n个数求和

ZZULIOJ

#include<iostream>
using namespace std;
const int N = 100010;
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i = 0; i < n; i ++){
		cin>>a[i];
	}
	int sum = 0;
	for(int i =0; i < n; i ++){
		sum +=a[i];
	}
	cout<<sum;
	return 0;

}

1040: 数列求和1

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	double sum = 0;
	for(double i = 1,j = 1; i <=n; i++,j = j +2){
		sum +=1/j;
	}
	printf("%.2lf",sum);
	return 0;
} 

1041: 数列求和2

ZZULIOJ

#include<iostream>

using namespace std;
int main(){
	int n;
	cin>>n;
	double sum = 0;
	for(double i = 1 ,j = 1; i <=n;i++,j =j + 2){
		if((int)i % 2 ==0){
			sum -= 1/j;
		
		}
		if((int)i % 2 !=0){
			sum += 1/j;
			
		}
	}
	printf("%.2lf",sum);
    return 0;
} 

1042: 数列求和3

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	double sum = 0;
	for(double i = 1, j = 1; i <=n; i++,j =j+2 ){
		if((int)i % 2 !=0){
			sum += i/j;
		}
		else{
			sum -= i/j; 
		}
	}
	printf("%.3lf",sum);
	return 0;
	
}

1043: 最大值

ZZULIOJ

#include<iostream>
using namespace std;

int main(){
	int n;
	cin>>n;
	int max;
	cin>>max;
	n--;
	while(n--)
	{
		int x;
		cin>>x;
		if(x > max) max = x;
	}
	cout<<max;
	return 0;
	
}

1044: 不及格率

ZZULIOJ

#include<iostream>
using namespace std;

int main(){
	int n;
	cin>>n;
	double sum =n;
	double cnt =0;
	while(n--){
		int x;
		cin>>x;
		if(x <60){
			cnt ++;
		}
	}

	printf("%.2lf",cnt/sum);
	return 0;
}

1045: 数值统计

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int cnt1 = 0;
	int cnt2 = 0;
	int cnt3 = 0;
	while(n--){
		int x;
		cin>>x;
		if(x < 0) cnt1 ++;
		if(x ==0) cnt2 ++;
		if(x >0) cnt3++;
	}
	cout<<cnt1<<" "<<cnt2<<" "<<cnt3<<endl;
	return 0;
}

1046: 奇数的乘积

ZZULIOJ

#include<iostream>
const int N = 100010;
int a[N];
using namespace std;
int main(){
	int n;
	int sum = 1;
	
	cin>>n;
	for(int i = 0; i < n;i ++) cin>>a[i];
	for(int i = 0; i < n; i ++){
		if(a[i] % 2 != 0){
		sum = sum *a[i];
		}
	}

	cout<<sum<<endl;
	return 0;
}

1047: 对数表

ZZULIOJ

对数:如果a的x次方等于N(a>0,且a≠1),那么数x叫做以a为底N的对数(logarithm),记作x=logaN。其中,a叫做对数的底数,N叫做真数。 [1]

自然对数:自然对数是数学中的一种特殊对数,它以常数e(欧拉数)为底的对数。自然对数常用符号"ln"表示,其定义为:ln(x) = loge(x)。简写log(x)。

#include<iostream>
#include<cmath>
using namespace std;

int main(){
	double n,m;
	cin>>n>>m;
	for(double i = n ; i <= m; i ++){
		printf("%4.0lf%8.4lf\n",i,log(i));
	 } 
	return 0;
	
}

1048: 阶乘表

ZZULIOJ

#include<iostream>
using namespace std;
long long int fact(int n){
	if(n ==1) return 1;
	
	else return n * fact(n-1);
}
int main(){
	int n;
	cin>>n;
	for(int i  = 1; i <=n; i ++){
		printf("%-4d%-20lld\n",i,fact(i));
	}
	
	return 0;
}

1049: 平方和与立方和

ZZULIOJ

#include<iostream>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int res1 =0;
	int res2 = 0;
	
	for(int i = n; i <= m; i++){
		if(i%2 ==0)
		{
			res1 += i*i;
		}
		else {
			res2 += i*i*i;
		}
	}
	
	cout<<res1<<" "<<res2<<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值