(杭电oj11页 (c++) 51-60

51、2051

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

string  check(int m)
{
	int n= m % 2, j=m/2;
	string s = to_string(n);
	while (j!=0)
	{
		n = j % 2;
		j = j / 2;
		
		s = s + to_string(n);
	}

	string k;
	for (int i = s.length()-1; i>=0; i--)
	{
		k = k + s[i];
	}
	return k;
}

int main()
{
	int m;
	while (cin >> m&&m>0&&m<1000)
	{
		cout << check(m) << endl;

	}
}

52、2052

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

void  draw(int m,int n)
{
	cout << "+";
	for (int i = 0; i < m; i++)
	{
		cout << "-";
	}
	cout << "+" << endl;
	for (int i = 0; i < n; i++)
	{
		cout << "|";
		for (int i = 0; i < m; i++)
		{
			cout << " ";
		}
		cout << "|"<<endl;
	}

	cout << "+";
	for (int i = 0; i < m; i++)
	{
		cout << "-";
	}
	cout << "+" << endl<<endl;

}

int main()
{
	int m,n;
	while (cin >> m&&m>0&&m<75)
	{
		cin.ignore();
		cin >> n;
		if (n > 0 && n < 75)
		{

		}
		draw(m, n);

	}
}

53、2053

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

int   check(int m)
{
	int n = 0;
	for (int i = 1; i <m+1; i++)
	{
		if (m % i == 0)
		{
			n++;
		}
	}
	if (n % 2 == 0)
	{
		return 0;
	}
	else {
		return 1;
	}
}

int main()
{
	int m,n;
	while (cin >> m&&m>0&&m <= 100000)
	{
			cout << check(m) << endl;	
	}
}

54、2054

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

string    check(string max,string min)
{
	if (max[0]=='-')
	{
		min ="-"+min;
	}
	if (max.find('.') != string::npos)
	{
		for (int i = max.length() - 1; i >= min.length(); i--)
		{
			if (max[i] == '0' || max[i] == '.') { max.erase(i); }
			else {
				return "NO";
			}

		}
	}
	if(max.length()!=min.length())return "NO";
	for(int i =0;i< min.length();i++)
	{ 
		if (max[i] != min[i])
		{
			return "NO";
		}
	}



	
	return "YES";
}

int main()
{
	string m,n;
	while (cin >> m)
	{
		cin.ignore();
		cin >> n;
		if(m.length()>=n.length())cout << check(m, n) << endl;
		if (m.length() < n.length())cout << check(n, m) << endl;
	}
}

55、2055

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

int     check(char x,int  y)
{
	int m = 0;
	if (x >= 'a'&&x<='z')
	{
		m = int('a') - int(x)-1;
	}
	else if(x >= 'A' && x <= 'Z') {
		m = int(x) - int('A') + 1;
	}
	return m+y;
}

int main()
{
	int n;
	while (cin >> n)
	{
		char x;
		int y;
		for (int i = 0; i < n; i++)
		{
			cin >> x;
			cin >> y;
			cout << check(x, y) << endl;
		}
	}
}

56、2056

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

double     check(double *x, double* y)
{

	double x1 = (x[1] < x[2] ? x[1] : x[2]) > (x[3] < x[4] ? x[3] : x[4]) ? (x[1] < x[2] ? x[1] : x[2]) : (x[3] < x[4] ? x[3] : x[4]);
	double y1 = (y[1] < y[2] ? y[1] : y[2]) > (y[3] < y[4] ? y[3] : y[4]) ? (y[1] < y[2] ? y[1] : y[2]) : (y[3] < y[4] ? y[3] : y[4]);
	double	x2 = (x[1] > x[2] ? x[1] : x[2]) < (x[3] > x[4] ? x[3] : x[4]) ? (x[1] > x[2] ? x[1] : x[2]) : (x[3] > x[4] ? x[3] : x[4]);
	double y2 = (y[1] > y[2] ? y[1] : y[2]) < (y[3] > y[4] ? y[3] : y[4]) ? (y[1] > y[2] ? y[1] : y[2]) : (y[3] > y[4] ? y[3] : y[4]);


	if (x2 - x1 <0||y2-y1<0) { return 0.00; }
	else { return (x2 - x1) * (y2 - y1); }
}

int main()
{
	double x[5],y[5];
	while (cin >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3] >> x[4] >> y[4])
	{
		cout << fixed << setprecision(2) << check(x, y) << endl;

	}
}

57、2057

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



int main()
{
	long long a,b;
	while (cin >>hex>>a>>b)
	{
		if (a + b < 0)
			cout << setiosflags(ios::uppercase) << hex << '-' << -(a + b) << endl;//16进制大写
		else
			cout << setiosflags(ios::uppercase) << hex << a + b << endl;
	}
	
}

58、2058

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

void print(int m, int n)
{
	int start = 0;
	for (int i = sqrt(2 * n); i >=1; i--)
	{
		start = (n - i * (i - 1) / 2) / i;
		if (n==start * i + (i * (i - 1)) / 2)
		{
			cout << "[" << start << "," << start+i-1 << "]" << endl;
		}
	}
	cout << endl;
}

int main()
{
	int a,b;
	while (cin >>a&&a>=1&&a<= 1000000000)
	{
		cin >> b;
		if (b >= 1 && b <= 1000000000)
		{
			print(a, b);
		}
	}
	
}

59、2059

#include<iostream>
#include<iomanip>
#include <cmath>
using namespace std;
const double INF = 0xfffff;//无穷大

double min(double a, double b)
{
	return a > b ? b : a;
}
int main()
{
	int l;
	int n, c, t;
	int vr, vt1, vt2;
	int p[103];
	while (cin >>l)
	{
		cin >> n;//充电站个数
		cin >> c;//电车行驶距离
		cin >> t;//充电时间
		cin >> vr;//兔子速度
		cin >> vt1;//电车速度
		cin >> vt2;//踩电车速度
		for (int i = 1; i < n+1; i++)
		{
			cin >> p[i];
		}
		double dp[103];
		dp[0] = 0; p[0] = 0; p[n + 1] = l;
		for (int i = 1; i < n + 2; i++)
		{
			dp[i] = INF;
			double t2;
			for (int j = 0; j < i; j++)
			{
				double len = p[i] - p[j];
				if (len > c)
				{
					t2 = (double)c / vt1 + (double)(len - c) / vt2;
				}
				else
				{
					t2 = (double)len / vt1;
				}
				t2 += dp[j];
				if (j > 0)//开始时是充满电的,无需充电时间
					t2 += t;
				dp[i] = min(dp[i], t2);//在第1、2...i-2、i-1轮循环中找到最短时间
			}
		}
		double tr = (double)l / vr;//兔子跑完全程所需时间
		if (dp[n + 1] < tr)
			cout << "What a pity rabbit!" << endl;
		else
			cout << "Good job,rabbit!" << endl;
	}
	
}

60、2060

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	while(cin>>n);
	{
		int m,a,b;
		cin>>m>>a>>b;
		if(m>6)
			a+=(m-6)*8+27;
		else
			 a=a+(15-m)*m/2; 
		if(a>=b)  
            cout<<"Yes"<<endl;  
        else  
            cout<<"No"<<endl;  
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值