东方博宜OJ答案 (1011~1020)

前言

欢迎大家能看到我的文章,这篇文章收录了东方博宜OJ 1011~1020所有题目的答案,后续还会往后出,敬请关注!如遇不足,欢迎指出!(不要喷我┭┮﹏┭┮)

注:部分源于其他博主!

1011

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int i, j;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n - i; j++)
		{
			cout << " ";
		}
		if (i == 1)
		{
			for (j = 1; j <= n; j++)
			{
				cout << "*";
			}
		}
		else
		{
			cout << "*";
			for (j = 1; j <= n + 2 * (i - 2); j++)
			{
				cout << " ";
			}
			cout << "*";
		}
		cout << endl;
	}
	for (i = n - 1; i >= 1; i--)
	{
		for (j = 1; j <= n - i; j++)
		{
			cout << " ";
		}
		if (i == 1)
		{
			for (j = 1; j <= n; j++)
			{
				cout << "*";
			}
		}
		else
		{
			cout << "*";
			for (j = 1; j <= n + 2 * (i - 2); j++)
			{
				cout << " ";
			}
			cout << "*";
		}
		cout << endl;
	}
	return 0;
}

1012

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	string str1;
	string str2;
	int num1 = 0;
	int word_number = 1;
	int nearest = 9999;
	int num2 = 0;
	getline(cin, str1);
	getline(cin, str2);
	str2 = " " + str2 ;//最重点!!在前面添加空格证明是单词,不然this中的is会被误判
	int a = str1.find(str2);
	if (a >= 0)
	{
		for (int i = 0; i < str1.size(); i++)
		{
			if (str1[i] == ' ')
			{
				num2++;
				if (abs(i - a) < nearest)
				{
					nearest = abs(i - a);
					if (nearest == 0)
					{
						break;
					}
				}
			}
		}
		cout << num2 + 1;
	}
	else if (a < 0)
	{
		for (int i = 0; i < str1.size(); i++)
		{
			if ((str1[i] > 64 && str1[i] < 91) || (str1[i] > 96 && str1[i] < 123))
			{
				num1++;
			}
		}
		cout << num1;
	}
	return 0;
}

1013

#include <iostream>
using namespace std;
int main()
{
	int t, x;
	for (int i = 100007; i < 999999; i += 10)
	{
		int t = i / 10;
		int x = 700000 + t;
		if (x % i == 0 && x / i == 4)
		{
			cout << i;
		}
	}
	return 0;
}

1014

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	int n;
	cin >> n;
	double sum = 0;
	for (double i = 1; i <= n; i++)
	{
		sum += 1.0 / i;
	}
	cout << fixed << setprecision(3) << sum;
	return 0;
}

1015

#include <iostream>
using namespace std;
int main()
{
	cout << 20 << " " << 30;
	return 0;
}

1016

#include <iostream>
using namespace std;
int main()
{
	int X, A, B;
	cin >> X >> A >> B;
	int num = 0;
	for (int i = 1; i <X/A+1; i++)
	{
		for (int j = 1; j <=X/B+1; j++)
		{
			if (i * A + j * B == X)
			{
				num++;
			}
		}
	}
	cout << num;
	return 0;
}

1017

#include <iostream>
using namespace std;
int main()
{
	cout << 173;
	return 0;
}

1018

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	int a[3];
	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
	}
	sort(a, a + 3);
	if (a[0] + a[1] > a[2] && pow(a[0], 2) + pow(a[1], 2) > pow(a[2], 2))
	{
		cout << "ruijiao";
	}
	else if (a[0] + a[1] > a[2] && pow(a[0], 2) + pow(a[1], 2) == pow(a[2], 2))
	{
		cout << "zhijiao";
	}
	else if (a[0] + a[1] > a[2] && pow(a[0], 2) + pow(a[1], 2) < pow(a[2], 2))
	{
		cout << "dunjiao";
	}
	else
	{
		cout << "no";
	}
	return 0;
}

1019

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	int num = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i; j > 0; j--)
		{
			num *= j;
		}
		sum += num;
		num = 1;
	}
	cout << sum;
	return 0;
}

1020

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	int a, b, c;
	a = n / 100;
	b = n % 100 / 10;
	c = n % 100 % 10;
	sum = n + 100 * c + 10 * b + a;
	cout << sum;
	return 0;
}
  • 12
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值