写在前面
这份文章会尽量多的收录东方博宜oj中的题目,会从最简单开始做起(博主只是一个学C++几个月还并非计算机专业也没有参加过信息竞赛的蒟蒻罢了),有的题简单的没有一点技术性可言(比如说手算出结果然后直接cout或者只用几个if语句就搞定的),但为了追求完整度还是基本上都写下来了,毕竟copy了可以直接粘贴然后刷AC(大雾),最后希望大家可以喜欢,再次重申本人真的只是初学者所以看到脑瘫的题解请不要喷我谢谢。
后续还会继续出关于东方博宜oj的答案,想要了解更多也欢迎关注谢谢!!!!!(orz)
1000
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
cin >> a >> b;
cout << a+b;
return 0;
}
1002
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
int sum = 0;
for (int i = 1; i <= a; i++)
{
sum += i;
}
cout << sum;
return 0;
}
1003
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
int sum = 0;
for (int i = 1; i <= a; )
{
sum += i;
i += 2;
}
cout << sum;
return 0;
}
1004
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
int sum = 1;
for (int i = 1; i <= a; i++)
{
sum *= i;
}
cout << sum;
return 0;
}
1005
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const double PI = 3.1415926;
int a;
cin >> a;
cout << fixed << setprecision(2) << PI * a * a << endl;
cout << fixed << setprecision(2) << 2 * PI * a;
return 0;
}
1006
这道题是我觉得在前面的嵌套循环题或者说是前面的题中我觉得比较难的一道了,考虑的时间会稍微长一点,毕竟它要有三个一样的东西,但是只要慢下心来拿笔谢谢其实还是比较简单的。
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= 6 * n - 3; j++)
{
if ((j >n-i && j < n+i) || (j > 3*n-i-1 && j < 3*n+i-1) || (j > 5 * n - i - 2 && j < 5 * n + i-2))
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
return 0;
}
1007
#include <iostream>
using namespace std;
int main()
{
char a[80];
int num = 0;
int num2 = 0;
for (int i = 0; i < 80; i++)
{
cin >> a[i];
num++;
if (a[i] == '.')
{
break;
}
}
for (int i = 0; i < num; i++)
{
if ((int)a[i] >= 65 && (int)a[i] <= 90)
{
num2++;
}
}
cout << num2;
return 0;
}
采用了强转将字母转成了ASCII码,A到Z对应ASCII码是65-90.不过这样子获取字符有一个缺点,就是如果重新输出的话空格是打不出来的,在网上找到了getchar()的一些用法但还没玩明白,等我慢慢学呜呜呜呜呜呜。
1008
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= 2 * n + 1; j++)
{
if (j>n-i&&j<n+i)
{
cout << i;
}
else
{
cout << " ";
}
}
cout << endl;
}
return 0;
}
注意换行的位置
1009
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int a[101];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = n-1; i >= 0; i--)
{
cout << a[i] << " ";
}
return 0;
}
1010
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int* p = new int[n];
for (int i = 0; i < n; i++)
{
cin >> p[i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (p[j] > p[j + 1])
{
int temp = p[j + 1];
p[j + 1] = p[j];
p[j] = temp;
}
}
}
for (int i = 0; i < n; i++)
{
cout << p[i] << " ";
}
delete[]p;
return 0;
}
冒泡排序法,当然用sort可以更快,权当复习一下冒泡,在堆区开辟内存的话记得delete
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;
}
1011本质也是嵌套循环的使用,不过可能在分类上比较复杂一点,这是东方博宜oj上的题解
1012是前五十题里最有挑战性的一道,也是最具价值的一道
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;//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))//ASCII码中字母对应的值
{
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;
}
1021
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 500; i++)
{
if (i % 3 == 2 && i % 5 == 3 && i % 7 == 2)
{
cout << i << endl;
}
}
return 0;
}
1022
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 20; i++)
{
for (int j = 30; j >= 0; j--)
{
if (7 * i + 4 * j == 100&&(100-i-j)%3==0)
{
cout << i << " " << j << " " << 100 - i - j << endl;
}
}
}
return 0;
}
1023
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
int num = 0;
if (n == 1)
{
cout << "F";
}
for (int i = 2; i < sqrt(n); i++)
{
if (n % i == 0&&n/i!=1&&n>=2)
{
num = 1;
cout << "F";
break;
}
}
if (num == 0&&n>=2)
{
cout << "T";
}
return 0;
}
1024
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
int num = 0;
for (int i = 1; i <= 63; i++)
{
for (int j = 1; j <= 250; j++)
{
for (int k = 1; k <= 500; k++)
{
if (i + j + k > 30 && 8 * i + 2 * j + k == 10 * n)
{
num++;
}
}
}
}
cout << num;
return 0;
}
1025
#include <iostream>
using namespace std;
int main()
{
cout << 461;
return 0;
}
1026
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a / b << " " << a % b;
return 0;
}
1027
#include <iostream>
using namespace std;
int main()
{
int n, n1, g, s, b;
cin >> n;
g = n % 10;
s = n % 100 / 10;
b = n / 100;
n1 = g + s + b;
cout << n1;
return 0;
}
1028
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,n1,g,s,b;
cin>>n;
g=n%10;
s=n%100/10;
b=n/100;
n1=g*100+s*10+b;
cout<<n1;
return 0;
}
1029
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int a = n / 1000;
int b = n % 1000 / 100;
int c = n % 1000 % 100 / 10;
int d = n % 1000 % 100 % 10;
cout << 1000 * d + 100 * c + 10 * b + a;
return 0;
}
1030
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if (a % b == 0)
{
cout << a / b;
}
else if (a % b != 0)
{
cout << a / b + 1;
}
return 0;
}
1031
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double n;
cin >> n;
double f = (9 * n + 160) / 5.0;
cout << fixed << setprecision(2) << f;
return 0;
}
1032
#include <iostream>
using namespace std;
int main()
{
int a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
if (a / 3 == 0)
{
a = 0;
}
else
{
a = (a - a % 3) / 3;
b += a;
e += a;
}
if (b / 3 == 0)
{
b = 0;
}
else
{
b = (b - b % 3) / 3;
c += b;
a += b;
}
if (c / 3 == 0)
{
c = 0;
}
else
{
c = (c - c % 3) / 3;
d += c;
b += c;
}
if (d / 3 == 0)
{
d = 0;
}
else
{
d = (d - d % 3) / 3;
c += d;
e += d;
}
if (e / 3 == 0)
{
e = 0;
}
else
{
e = (e - e % 3) / 3;
a += e;
d += e;
}
cout << a << " " << b << " " << c << " " << d << " " << e;
return 0;
}
很sb的做法....只能说本人水平就这样了,本来想用循环的,但由于5号小朋友要把糖果分给1号所以一下子没想到很好的解决方案,把abcde给转换成ASCII码也不是很方便,索性用最笨比的做法。
1033
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if (n % 2 == 0)
{
cout << "y e s";
}
else
{
cout << "n o";
}
return 0;
}
1034
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if (a > b)
{
cout << a;
}
else
{
cout << b;
}
return 0;
}
1035
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if (n >= 86)
{
cout << "VERY GOOD";
}
else if (n >= 60 && n < 86)
{
cout << "GOOD";
}
else
{
cout << "BAD";
}
return 0;
}
1036
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
if (a + b > c)
{
cout << "yes";
}
else
{
cout << "no";
}
return 0;
}
1037
#include <iostream>
using namespace std;
int main()
{
double n;
cin >> n;
if (n < 1.3)
{
cout << "60";
}
else
{
cout << "120";
}
return 0;
}
1038
#include <iostream>
using namespace std;
int main()
{
int x;
cin >> x;
if (x > 0)
{
cout << x + 1;
}
else if (x == 0)
{
cout << 0;
}
else
{
cout << x - 1;
}
return 0;
}
1039
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
int d;
cin >> a >> b >> c;
d = (a > b) ? (a > c ? a : c) : (b > c ? b : c);
cout << d;
return 0;
}
1040
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a > b;
}
int main()
{
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3, cmp);
for (int i = 0; i < 3; i++)
{
cout << a[i] << " ";
}
return 0;
}
1041
#include <iostream>
#include <algorithm>
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] + 1 == a[1] && a[1] + 1 == a[2])
{
cout << "TRUE";
}
else
{
cout << "FALSE";
}
return 0;
}
1042
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
int a, b, c;
a = n / 100;
b = n % 100 / 10;
c = n % 100 % 10;
int d[3];
d[0] = a;
d[1] = b;
d[2] = c;
sort(d, d + 3);
cout << d[2] * 100 + d[1] * 10 + d[0];
return 0;
}
感觉复杂了点..不过看到题目一下子就蹦出来这个思路,题也不难,干脆就这样吧(摆烂
1043
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
cin >> n;
double num = 0;
if (n <= 10)
{
num = 2.5;
cout << fixed << setprecision(2) << num;//保留小数,需要iomanip头文件
}
if (n > 10)
{
num = 1.5 * n - 12.5;
cout << fixed << setprecision(2) << num;
}
return 0;
}
1044
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
if (n < 10)
{
cout << 'A';
}
else if (n >= 10 && n < 20)
{
cout << 'B';
}
else if (n >= 20 && n < 40)
{
cout << 'C';
}
else if (n >= 40 && n < 50)
{
cout << 'D';
}
else if (n >= 50 && n < 80)
{
cout << 'E';
}
return 0;
}
1045
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] + a[1] > a[2])
{
cout << "Yes";
}
else
{
cout << "No";
}
return 0;
}
1046
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int a[4];
for (int i = 0; i < 4; i++)
{
cin >> a[i];
}
sort(a, a + 4);//升序排列
if (a[0] + 2 == a[1] && a[1] + 2 == a[2] && a[2] + 2 == a[3])
{
cout << a[0] << "+2=" << a[1] << endl;
cout << a[1] << "+2=" << a[2] << endl;
cout << a[2] << "+2=" << a[3];
}
else
{
sort(a, a + 4, cmp);//降序排列
for (int i = 0; i < 4; i++)
{
cout << a[i] << " ";
}
}
return 0;
}
1047
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double a[3];
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] + a[1] > a[2] && pow(a[0], 2) + pow(a[1], 2) == pow(a[2], 2))
{
cout << fixed << setprecision(1) << a[0] * a[1] / 2.0;
}
else
{
cout << "No";
}
return 0;
}
1048
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if ((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1))
{
cout << "win";
}
else if (a == b)
{
cout << "tie";
}
else
{
cout << "lose";
}
return 0;
}
1049文章来源:https://www.toymoban.com/news/detail-520247.html
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
if (n == 1)
{
cout << "one";
}
else if (n == 2)
{
cout << "two";
}
else if (n == 3)
{
cout << "three";
}
else if (n == 4)
{
cout << "four";
}
else if (n == 5)
{
cout << "five";
}
else if (n == 6)
{
cout << "six";
}
else if (n == 7)
{
cout << "seven";
}
else if (n == 8)
{
cout << "eight";
}
else if (n == 9)
{
cout << "nine";
}
else
{
cout << "out";
}
return 0;
}
1050文章来源地址https://www.toymoban.com/news/detail-520247.html
#include <iostream>
using namespace std;
int main()
{
int a[4];
int num = 0;
int judge = 0;
for (int i = 0; i < 4; i++)
{
cin >> a[i];
if (a[i] >= 90)
{
num++;
}
if (a[i] < 60)
{
cout << "Poor LanYangYang";
judge = 1;
break;
}
}
if (judge == 0 && num != 4)
{
cout << num;
}
if (judge == 0 && num == 4)
{
cout << 5;
}
return 0;
}
到了这里,关于东方博宜oj答案的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!