东华考研复试1-10oj

1. 求长方形的面积和周长

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

int main() {
	int a, b,s, p;
	
	while(cin>>a>>b){
		s = a * b;
		p = 2 * (a + b);
		cout<<s<<" "<<p<<endl;
	}
	return 0;
}

2. 数列和

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

int main() {
	int n, sum;
	
	while(cin>>n){
		sum = n * (n + 1) / 2;
		cout<<sum<<endl;
	}
	return 0;
}

3. 解方程

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

int main() {
	double a, b, x;
	
	while(cin>>a>>b){
		x = (5 - 3 *b) / (2 * a);
		cout<<fixed<<setprecision(1)<<x<<endl;
	}
	return 0;
}

4. 一个月的天数

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

int main() {
	int year, mouth, day;
	
	while(cin>>year>>mouth){
		if (year % 400 ==0 || year % 100 != 0 && year % 4 == 0) {
			if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12) {
				cout<<31<<endl;
			} else if (mouth == 2) {
				cout << 29 <<endl;
			} else if (mouth == 4 || mouth == 6 || mouth == 9 || mouth == 11) {
				cout<<30<<endl;
			}
		} else {
			if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12) {
				cout<<31<<endl;
			} else if (mouth == 2) {
				cout<<28<<endl;
			} else if(mouth == 4 || mouth == 6 || mouth == 9 || mouth == 11) {
				cout<<30<<endl;
			}
		}
	}
	return 0;
}

5. 银行存款到期日

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

int main() {
	int year, mouth, day, num, y, m, d;
	while(cin>>year>>mouth>>day>>num){
		y = year;
		m = mouth + num;
		d = day;
		while (m > 12) {
			m -= 12;
			y++;
		}
		if(m==2) {
			if (y % 400 == 0 ||( y%100!=0 &&y % 4 ==0)){
				d = 29;
			}	
		 else {
			d = 28;
		}
		}
		if ((m == 4 && d >30 )|| (m == 6 && d >30)|| (m == 9 && d >30)||( m == 11&& d >30)) {
			d = 30;
		} 
		cout <<y<<" "<<m<<" "<< d << endl;
		
	}
		
	return 0;
}

6.实数运算

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

int main() {
	double a, b;
	char ch;
	
	while(cin>>a>>b){
		cin>>ch;
		if (b != 0){
			if (ch == '+') {
				cout <<fixed << setprecision(1) << a + b <<endl;
			} else if (ch == '-') {
				cout <<fixed << setprecision(1) << a - b <<endl;
			} else if (ch == '*') {
				cout <<fixed << setprecision(1) << a * b <<endl;
			} else if (ch == '/') {
				cout <<fixed << setprecision(1) << a / b <<endl;
			}
		} else {
			cout << "Wrong!" <<endl;
		}
	}
		
	return 0;
}

7.解二次方程

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

int main() {
	int a,b, c;
	double x1, x2, d;
	while(cin>>a>>b>>c){
		d = b*b-4*a*c;
		x1= ((-b)+sqrt(d))/(2* a) ;
		x2 = ((-b)-sqrt(d))/(2* a) ;
		if(x1 > x2){
			cout << fixed <<setprecision(2) << x1 <<" "<< x2 <<endl;
		} else {
			cout << fixed <<setprecision(2) << x2 <<" "<< x1 <<endl;
		}
	}
	return 0;
}

8. 门票价格计算

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

int main() {
	int n;
	double s;
	while(cin>>n){
		if (0 <= n && n <=20) {
			s=n * 5;
		} else if(n > 20 && n <= 40) {
			s = n * 5 * 0.9;
		} else if (n > 40 && n <= 80) {
			s = n * 5 * 0.85;
		} else if (n > 80 && n <= 120) {
			s = n * 5 * 0.8;
		} else if (n > 120) {
			s = n * 5 * 0.7;
		}
		cout<<fixed<<setprecision(2)<<s<<endl;
	}
		
	return 0;
}

9.星期几问题

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

int main() {
	int n;
	string ch;
	while(cin>>n){
		if (n == 0) {
			ch = "Sunday";
		} else if(n == 1) {
			ch = "Monday";
		} else if (n == 2) {
			ch = "Tuesday";
		} else if (n == 3) {
			ch = "Wednesday";
		} else if (n == 4) {
			ch = "Thursday";
		} else if (n == 5) {
			ch = "Friday";
		} else if (n == 6) {
			ch = "Saturday";
		}
		cout<<ch<<endl;
	}
		
	return 0;
}

10.时间相加

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

int main() {
	int a , b, c, d, e, f, s, i, m;
	while(cin>>a>>b>>c>>d>>e>>f){
		s = a + d;
		i = b + e;
		m = c + f;
		if(m >= 60) {
			m -= 60;
			i++;
		}
	    if(i >= 60) {
			i -= 60;
			s++;
		} 
		cout<<s<<" "<<i<<" "<<m<<endl;
	}
		
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值