东方博宜OJ答案与解析(1011~1015)

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 <bits/stdc++.h>
using namespace std;
int main()
{
	string str1,str2;
	int num1 = 0,word_number = 1,nearest = 9999,num2 = 0;
	getline(cin,str1);
	getline(cin,str2);
	str2=" " +str2 ;
	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 <bits/stdc++.h>
using namespace std;
int main()
{
    cout<<"179487";
    return 0;
}

1014 - 编程求1+1/2+1/3+...+1/n

#include<bits/stdc++.h>
using namespace std;
int main()
{
	float n,sum=1;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		sum+=1.0/i;
	}
	printf("%.3lf",sum);
	return 0;
}

1015 - 鸡兔同笼问题

#include <bits/stdc++.h>

using namespace std;

int main(){
	for(int i=0;i<=50;i++)
	{
		if(i*4+(50-i)*2==160)
		{
			cout<<50-i<<" "<<i<<endl;
		}
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值