传送门

东方博宜oj答案_like_astar的博客-CSDN博客东方博宜oj答案1000-1050https://blog.csdn.net/like_astar/article/details/128881011

有要说的话已经在第一篇文章里说过了,这里不多赘述,直接进入主题,如果哪里做的不好也欢迎在评论区留言。

1051

#include <iostream>
using namespace std;
int main()
{
	double a, b, c;//设置为double是为了方便除法,如果是int的话除出来都是整数
	cin >> a >> b >> c;
	int num;
	if (c - b == b - a && c / b != b / a)//等差数列
	{
		num = c - b;
		cout << c + num << " " << c + 2 * num << " " << c + 3 * num;
	}
	if (c - b != b - a && c / b == b / a)//等比数列
	{
		num = c / b;
		cout << c * num << " " << c * num * num << " " << c * num * num * num;
	}
	if (a == b && b == c)//常数列,既是等差数列又是等比数列
	{
		cout << a << " " << a << " " << a;
	}
	return 0;
}

1052

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	double n;
	cin >> n;
	if (n <= 15)
	{
		cout << fixed << setprecision(2) << n/1.5;
	}
	if (n > 15)
	{
		cout << fixed << setprecision(2) << (n + 10) / 2.5;
	}
	return 0;
}

简单的小学数学,注意小数的位数输出

1053

#include <iostream>
using namespace std;
int main()
{
	int sum = 0;
	for (int i = 1; i <= 100; i += 3)
	{
		sum += i;
	}
	cout << sum;
	return 0;
}

1054

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += pow(i,2);
	}
	cout << sum;
	return 0;
}

1055

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 2 && i % 5 == 3 && i % 7 == 2)
		{
			sum++;
		}
	}
	cout << sum;
	return 0;
}

1056

#include <iostream>
using namespace std;
int main()
{
	int sum = 0;
	for (int i = 1; i <= 1000; i++)
	{
		if (i / 100 == 3 || i % 100 / 10 == 3 || i % 100 % 10 == 3)//个位十位百位有一个有3就彳亍
		{
			sum++;
		}
	}
	cout << sum;
	return 0;
}

1057

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 5; i <= n; i += 5)
	{
		if (i/10000==5||i%10000/1000==5||i%10000%1000/100==5||i%10000%1000%100/10==5||i%10000%1000%100%10==5)
		{
			sum++;
		}
	}
	cout << sum;
	return 0;
}

1058

#include <iostream>
using namespace std;
int main()
{
	int num = 100;
	while (num < 1000&& num > 99)
	{
		int a, b, c;
		a = num / 100;
		b = num % 100 / 10;
		c = num % 100 % 10;
		if (a * a * a + b * b * b + c * c * c == num)
		{
			cout << num << endl;
		}
		num++;
	}
	return 0;
}

1059

#include <iostream>
using namespace std;
int main()
{
	for (int i = 1; i <= 999; i++)
	{
		if (i % 3 == 0)
		{
			if (i / 100 == 5 || i % 100 / 10 == 5 || i % 100 % 10 == 5)
			{
				cout << i << endl;
			}
		}
	}
	return 0;
}

1060

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	if (n % 2 != 0)//只因
	{
		for (int i = 2; i < n; i++)
		{
			if (i % 2 == 0)
			{
				sum += i;
			}
		}
	}
	if (n % 2 == 0)//偶
	{
		for (int i = 1; i <= n; i++)
		{
			if (n % i == 0)
			{
				sum += i;
			}
		}
	}
	cout << sum;
	return 0;
}

1061

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int judge = 1;//judge用来判断
	int i;//把i放在外面,如果在里面当for循环完成之后i就会被清掉
	for (i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0)//合数
		{
			judge = 0;
			break;
		}
	}
	if (judge == 1)//说明它是个质数
	{
		cout << "Yes";
	}
	if (judge == 0)
	{
		cout << i;
	}
	return 0;
}

1062

#include <iostream>
using namespace std;
int main()
{
	double i = 100;
	int num = 0;
	while (i >= 0.5)
	{
		i /= 2;
		num++;
	}
	cout << num;
	return 0;
}

1063

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int m, n;
	cin >> m >> n;
	int sum = 0;
	for (int i = m; i <= n; i++)
	{
		int judge = 1;
		if (i == 1)//1既不是质数也不是合数
		{
			continue;
		}
		for (int j = 2; j <= sqrt(i); j++)
		{
			if (judge == 0)
			{
				continue;
			}
			if (i % j == 0)
			{
				judge = 0;
			}
		}
		if (judge == 1)
		{
			sum++;
		}
	}
	cout << sum;
	return 0;
}

题目说的是两个数之间,按道理是不包含这两个数的,结果WA了好几次,真无语了..

1064

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int num = 0;
	for (int i = 1; i <= n; i++)
	{
		int judge = 1;
		if (i == 1)//1既不是质数也不是合数
		{
			continue;
		}
		for (int j = 2; j <= sqrt(i); j++)
		{
			if (judge == 0)
			{
				continue;
			}
			if (i % j == 0)
			{
				judge = 0;
			}
		}
		if (judge == 1)
		{
			cout << i << " ";
			num++;
			if (num == 5)
			{
				cout << endl;
				num = 0;
			}
		}
	}
	return 0;
}

1065(1065-1072全是画图形的嵌套循环练习)

如果往后看的话与之前1006的题解对比的话会发现我下面for里面放了两个循环。虽说这样子运行起来会慢一点(可能?我只是听说循环的复杂度高还是什么鬼的不确定啊啊啊还没学),但是这样子比较直观。

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

1066

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

1067

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

1068

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

1069

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

1070

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

1071

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

与1011有点类似,这种上下比较对称的形状一般分类讨论的话都可以解决

1072

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

1073

本道题采用了下面这位博主的答案

版权声明:本文为CSDN博主「虫卅」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_35463630/article/details/121218654 

原谅我我写嵌套循环真的要写吐了呜呜呜

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int i = (n+1)/2-1;i>=0;i--){
		for(int j=1;j<=(n+1)/2-i-1;j++){
			cout<<" ";
		}
		for(int j=1;j<=2*i+1;j++){
			cout<<"*";
		}	
		cout<<endl;
	}
	for(int i = 1;i<=n/2;i++){
		for(int j=1;j<=n/2-i;j++){
			cout<<" ";
		}
		for(int j=1;j<=2*i+1;j++){
			cout<<"*";
		}	
		cout<<endl;
	}

	return 0;
}

1074

#include <iostream>
using namespace std;
int main()
{
	int m, n, h;
	cin >> m >> n >> h;
	int num = 0;
	int sum = 0;
	while (1)
	{
		if (m + sum < h)
		{
			sum += m - n;
			num++;
		}
		if (m + sum >= h)
		{
			num++;
			break;
		}
	}
	cout << num;
	return 0;
}

1075

这个是正确答案。

#include <iostream>
using namespace std;
int main()
{
	long long n, x;
	cin >> n;
	x = 2;
	while (x <= n)
	{
		x = x * 2;
	}
	if (x - n < n - x / 2)
	{
		cout << x;
	}
	else
	{
		cout << x / 2;
	}
	return 0;
}

这个是我一开始的答案,第一次提交的时候是对的但是后来不知道为什么就不行了,就挺离谱的。

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int min = 2 * pow(10, 9);
	int i = 3;
	while (1)
	{
		if (abs(pow(2, i) - n) < min)
		{
			min = abs(pow(2, i) - n);
		}
		if (abs(pow(2, i + 1)) - n >= min)
		{
			break;
		}
		i++;
	}
	cout << pow(2, i);
	return 0;
}

这个是我在看到有人评论我说答案错了之后我重新写的,这个比之前写的要简洁一些,但是也不行。关键是我也想不到到底哪里错,也不是什么难题。如果有人发现这下面两个有什么我没找到的问题的话请立刻私聊或评论。

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long long int n;
	long long int min = 2147483647;
	long long int num = 0;
	for (int i = 0; i <= 31; i++)
	{
		if (abs(pow(2, i) - n) < min)
		{
			min = abs(pow(2, i) - n);
			num = pow(2, i);
		}
	}
	cout << num << endl;
}

1076

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int num = 0;
	for (int i = 0; i <= 11; i++)//鸟
	{
		for (int j = 0; j <= 50; j++)//只因
		{
			for (int k = 0; k <= 25; k++)//兔
			{
				if (9 * i + j + k == 100 && 2 * i + 2 * j + 4 * k == 100)
				{
					cout << i << " " << j << " " << k << endl;
					num++;
				}
			}
		}
	}
	cout << num;
	return 0;
}

1077

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

1078

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	double s = 0;
	int i;
	for (i = 1;; i++)
	{
		s += 1.0 / i;
		if (s > n)
		{
			break;
		}
	}
	cout << i;
	return 0;
}

1079

#include <iostream>
using namespace std;
int main()
{
	int L;
	cin >> L;
	int num = 0;
	int num1 = 0;//有两条边相等
	int num2 = 0;//三条边都不相等
	for (int i = 1; 2*i < L; i++)
	{
		for (int j = 1; 2*j < L; j++)
		{
			if (i+j<L&&2*i+2*j>L&&L-i-j>0)//这是成为三角形的条件,经过化简之后得到可以自己算算
			{
				if (!(3*i==L&&3*j==L&&3*(L-i-j)==L))//括号内是等边三角形的情况,前面加上!为非等边三角形
					//一定要注意这里不能写成i!=j&&j!=L-i-j&&i!=L-i-j,因为这样等腰三角形的情况会被吞掉
				{
					if (i != j && j != (L - i - j) && i != (L - i - j))
					{
						num2++;
					}
					else
					{
						num1++;
					}
				}
			}
		}
	}
	num = num1 / 3 + num2 / 6;//两条边相等的排列方式有3种,三条边互异的排列方式有6种
	cout << num;
	return 0;
}

1080

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int i = 2;//除数
	while (!(n == 1))
	{
		if (n % i == 0)
		{
			n /= i;
			cout << i << endl;
			i = 2;
		}
		else
		{
			i++;
		}
	}
	return 0;
}

1081

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a;
	int b;
	int c;
	a = n / 3600;
	b = n % 3600 / 60;
	c = n % 3600 % 60;
	cout << setw(2) << setfill('0') << a << ":"
		<< setw(2) << b << ":"
		<< setw(2) << c << endl;
	return 0;
}

1082

简单的手算

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

1083

#include <iostream>
#include <cmath>
using namespace std;
bool judge(int n)//判断回文数函数
{
	int num = 0;//记录位数
	int sum = 0;
	for (int i = 1; n / i != 0; i *= 10)//判断位数
	{
		if (n / i != 0)
		{
			num++;
		}
	}
	for (int i = 1; i < num; i++)
	{
		sum += (n - n / (int)pow(10, i) * (int)pow(10, i)) / (int)pow(10, i - 1) * (int)pow(10, num - i);
	}//注意pow函数在使用的时候会发生隐式转换,返回的是double类型,所以要强转成int类型
	sum += n / pow(10, num - 1);
	if (sum == n)
	{
		return true;
	}
	else
	{
		return false;
	}
}
int produce(int &n)//生成回文数
{
	int num = 0;//记录位数
	int sum = 0;
	for (int i = 1; n / i != 0; i *= 10)//判断位数
	{
		if (n / i != 0)
		{
			num++;
		}
	}
	for (int i = 1; i < num; i++)
	{
		sum += (n - n / (int)pow(10, i) * (int)pow(10, i)) / (int)pow(10, i - 1) * (int)pow(10, num - i);
	}
	sum += n / pow(10, num - 1);
	n = n + sum;
	return n;
}
int main()
{
	int n;
	cin >> n;
	judge(n);
	if (judge(n) == true)
	{
		cout << 0;
		return 0;
	}
	else
	{
		int num = 0;
		while (judge(n) == false)
		{
			produce(n);
			num++;
		}
		cout << num;
		return 0;
	}
}

1084

#include <iostream>
#include <cmath>
using namespace std;
int sumOfFactors(int n) {
	int sum = 0; 
	int sqrtN = sqrt(n);
	for (int i = 2; i <= sqrtN; ++i) {
		if (n % i == 0) {
			sum += i;
			if (i != n / i) { 
				sum += n / i;
			}
		}
	}
	return sum;
}

int main() {
	int number;
	cin >> number;
	int result = sumOfFactors(number);
	cout << result;
	return 0;
}

1085

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int a, b, c, d;
	
	for (int i = 1000; i <= 9999; i++)
	{
		a = i / 1000;
		b = i % 1000 / 100;
		c = i % 1000 % 100 / 10;
		d = i % 1000 % 100 % 10;
		if (pow(10 * a + b + 10 * c + d, 2) == 1000 * a + 100 * b + 10 * c + d)
		{
			cout << i << endl;
		}
	}
	return 0;
}

1086

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if ((i + j) % 3 == 0 || (i + j) % 7 == 0)
			{
				sum++;
			}
		}
	}
	cout << sum;
	return 0;
}

1087

注意数据的范围,要加long long不然会WA,就因为这个WA了一回,超

#include <iostream>
using namespace std;
int main()
{
	long long int m, n, a, b, r;
	cin >> m >> n;
	if (m > n)
	{
		a = m;
		b = n;
	}
	else
	{
		a = n;
		b = m;
	}
	r = b;
	while (r != 0)
	{
		r = a % b;
		a = b;
		b = r;
	}//辗转相除法求最大公约数
	m /= a;
	n /= a;
	cout << a * m * n;//求最小公倍数
	return 0;
}

1088

乐,感觉1087和1088放反了,1088就是1087要用的

#include <iostream>
using namespace std;
int main()
{
	long long int m, n, a, b, r;
	cin >> m >> n;
	if (m > n)
	{
		a = m;
		b = n;
	}
	else
	{
		a = n;
		b = m;
	}
	r = b;
	while (r != 0)
	{
		r = a % b;
		a = b;
		b = r;
	}
	cout << a;
	return 0;
}

1089

#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	for (int i = 100; i <= 999; i++)
	{
		a = i / 100;
		b = i % 100 / 10;
		c = i % 100 % 10;
		if (!(a == b || b == c||a==c))
		{
			if (b > a + c)
			{
				if (a + b != 3 && a + b != 5 && a + b != 7 && a + b != 11 && a + b != 13&& a + b != 17)//本来按道理判断是不是质数应该再写一个小程序的但是因为数不大所以干脆枚举算了,运行的还快
				{
					cout << i << endl;
				}
			}
		}
	}
	return 0;
}

1090

#include <iostream>
using namespace std;
int main()
{
	for (int i = 10; i <= 1000; i++)
	{
		if (i % 2 == 0 && i % 3 == 0 && i % 7 == 0)
		{
			cout << i << endl;
		}
	}
	return 0;
}

1091

#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int sum1 = 0;//奇数和
	int sum2 = 0;//偶数和
	for (int i = 1; i <= n; i++)
	{
		if (i % 2 == 0)
		{
			sum2 += i;
		}
		else
		{
			sum1 += i;
		}
	}
	cout << sum1 << " " << sum2;
	return 0;
}

1092

aabb还有完全平方数的这两个限制条件是非常强的,稍微一想就知道这样的数不会很多,所以不如找出四位数的完全平方数然后肉眼找一找哪个是aabb型的就好了。

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

1093

极致的偷鸡

#include <iostream>
using namespace std;
int main()
{
	string a = "abcdefghijklm";
	string b = "nopqrstuvwxyz";
	string c = "zyxwvutsrqpon";
	string d = "mlkjihgfedcba";
	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
	cout << d;
	return 0;
}

1094

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

1095

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

1096

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

1097

#include <iostream>
using namespace std;
int main()
{
	char a[21];
	int num = 0;
	for (int i = 0; i < 21; i++)
	{
		cin >> a[i];
		num++;
		if (a[i] == '#')
		{
			break;
		}
	}
	int num1 = 0, num2 = 0, num3 = 0;//大写,小写,数字
	for (int i = 0; i < num; i++)
	{
		if (a[i] >= 65 && a[i] <= 90)
		{
			num1++;
		}
		if (a[i] >= 97 && a[i] <= 122)
		{
			num2++;
		}
		if (a[i] >= 48 && a[i] <= 57)
		{
			num3++;
		}
	}
	cout << num1 << " " << num2 << " " << num3;
	return 0;
}

1098

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a;
	getline(cin, a);
	int num = 1;
	if (a.size() % 2 == 0)//数字有奇数个,因为还有个"."
	{
		for (int i = 0; i < a.size() / 2 - 1; i++)
		{
			if (a[i] == a[a.size() - 2 - i])
			{

			}
			else
			{
				num = 0;
				break;
			}
		}
	}
	else//数字有偶数个
	{
		for (int i = 0; i <= (a.size() - 1) / 2; i++)
		{
			if (a[i] == a[a.size() - 2 - i])
			{

			}
			else
			{
				num = 0;
				break;
			}
		}
	}
	if (num == 1)
	{
		cout << "TRUE";
	}
	else
	{
		cout << "FALSE";
	}
	return 0;
}

1099

这真的是基础而不是入门题吗..

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a;
	getline(cin, a);
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] == 79)
		{
			a[i] = 48;
		}
		if (a[i] == 108)
		{
			a[i] = 49;
		}
		if (a[i] == 90)
		{
			a[i] = 50;
		}
		if (a[i] == 83)
		{
			a[i] = 53;
		}
		if (a[i] == 98)
		{
			a[i] = 54;
		}
		if (a[i] == 66)
		{
			a[i] = 56;
		}
		if (a[i] == 113)
		{
			a[i] = 57;
		}
	}
	cout << a;
	return 0;
}

1100

用ASCII码来判断

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a;
	getline(cin, a);
	//这道题虽然看起来难度不大但是稍微有不注意还是很容易WA的,下面提几个容易WA的点
	//1.空格可以有多个,所以如果找单词首字母采用空格位置+1的话可能下一个位置还是空格,就容易错
	//2.字母可以大小写,等会给几个我用过的测试案例
	//3.开头可以有空格,这个是最坑的,因为开头有没有空格并不像后面说单词单词之间一定有空格这么绝对,所以这里我把
	//  开头有无空格单拎出来进行讨论,而且开头也可以有多个空格
	//4.测试案例,就用题目给的end of file就可以:
	/*
        (开头)end of file
		(开头)End of File
		(开头)end             of File
		(开头)      end         of  File
	*/
	int i = 0;
	while (a[i] == ' ')
	{
		i++;
	}
	if (a[i] > 90)
	{
		a[i] -= 32;
		cout << a[i];
	}
	else
	{
		cout << a[i];
	}
	for (i; i < a.size(); i++)
	{
		if (a[i] == ' ')
		{
			if (a[i + 1] == ' ')
			{
				continue;
			}
			if (a[i + 1] > 90)
			{
				a[i + 1] -= 32;
				cout << a[i + 1];
			}
			else
			{
				cout << a[i + 1];
			}
		}
	}
	return 0;
}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐