49(2023.12.16)(抓牛牛,多项式,字符串展开)

49(2023.12.16)(抓牛牛,多项式,字符串展开)_第1张图片

#include
using namespace std;
int main()
{
	char ch;
	char arr[11][11];
	int fx1 = 1;
	int fx2 = 1;
	int x1, y1, x2, y2;
	for (int i = 0;i < 10;i++)
	{
		for (int j = 0;j < 10;j++)
		{
			cin >> ch;
			if (ch == 'C')
			{
				x1 = i;
				y1 = j;
				arr[i][j] = '.';
			}
			else if (ch == 'F')
			{
				x2 = i;
				y2 = j;
				arr[i][j] = '.';
			}
			else
			{
				arr[i][j] = ch;
			}
		}
	}
	int times = 0;
	while (x1 != x2 || y1 != y2)
	{
		times++;
		if (fx1 == 1)
		{
			if (arr[x1 - 1][y1] == '.')
			{
				x1--;
			}
			else
			{
				fx1 = 2;
			}
		}
		else if (fx1 == 2)
		{
			if (arr[x1][y1 + 1] == '.')
			{
				y1++;
			}
			else
			{
				fx1 = 3;
			}
		}
		else if (fx1 == 3)
		{
			if (arr[x1 + 1][y1] == '.')
			{
				x1++;
			}
			else
			{
				fx1 = 4;
			}
		}
		else if (fx1 == 4)
		{
			if (arr[x1][y1 - 1] == '.')
			{
				y1--;
			}
			else
			{
				fx1 = 1;
			}
		}
		if (fx2 == 1)
		{
			if (arr[x2 - 1][y2] == '.')
			{
				x2--;
			}
			else
			{
				fx2 = 2;
			}
		}
		else if (fx2 == 2)
		{
			if (arr[x2][y2 + 1] == '.')
			{
				y2++;
			}
			else
			{
				fx2 = 3;
			}
		}
		else if (fx2 == 3)
		{
			if (arr[x2 + 1][y2] == '.')
			{
				x2++;
			}
			else
			{
				fx2 = 4;
			}
		}
		else if (fx2 == 4)
		{
			if (arr[x2][y2 - 1] == '.')
			{
				y2--;
			}
			else
			{
				fx2 = 1;
			}
		}
		if (times > 1000)
		{
			cout << 1 << endl;
			return 0;
		}
	}
	cout << times << endl;
	system("pause");
	return 0;
}

49(2023.12.16)(抓牛牛,多项式,字符串展开)_第2张图片 

#include
using namespace std;
int main()
{
	int n;
	cin >> n;
	int num;
	int arr[101] = { 0 };
	for (int i = 0;i <= n;i++)
	{
		cin >> num;
		arr[i] = num;
	}
	if (n == 0)
	{
		cout << num;
		return 0;
	}
	int times = n;
	int test = 1;
	for (int i = 0;i < n;i++)
	{
		if(times!=0&&arr[i]!=0)
		{
			if (test == 1)
			{
				test = 0;
			}
			else
			{
				if (arr[i] > 0)cout << "+";
			}
			if (arr[i] == 1)cout << "x";
			else if (arr[i] == -1)cout << "-x";
			else cout << arr[i] << "x";
			if (times != 1)cout << "^" << times;
		}
		times--;
	}
	if (arr[n] != 0)
	{
		if (arr[n] > 0)cout << "+" << arr[n];
		else if (arr[n] < 0)cout << arr[n];
	}
	system("pause");
	return 0;
}

 49(2023.12.16)(抓牛牛,多项式,字符串展开)_第3张图片

#include
using namespace std;
#include
#include
int main()
{
	int p1, p2, p3;
	cin >> p1 >> p2 >> p3;
	string str;
	cin >> str;
	int l = str.length();
	vectorv;
	int a;
	for (int i = 0;i < l;i++)
	{
		if (str[i] == '-')
		{

			if (i == 0 || i == (l - 1))cout << '-';
			else if ((int)str[i + 1] - (int)str[i - 1] == 1);
			else if ((int)str[i + 1] <= (int)str[i - 1])
			{
				cout << '-';
			}
			else if (((int)str[i-1]>=48&& (int)str[i - 1]<=57)&&
				!((int)str[i + 1] >= 48 && (int)str[i + 1] <= 57))
			{
				cout << '-';
			}
			else if (!((int)str[i - 1] >= 48 && (int)str[i - 1] <= 57) &&
				((int)str[i + 1] >= 48 && (int)str[i + 1] <= 57))
			{
				cout << '-';
			}

			else if (((int)str[i - 1] >= 65 && (int)str[i - 1] <= 90) &&
				!((int)str[i + 1] >= 65 && (int)str[i + 1] <= 90))
			{
				cout << '-';
			}
			else if (!((int)str[i - 1] >= 65 && (int)str[i - 1] <= 90) &&
				((int)str[i + 1] >= 65 && (int)str[i + 1] <= 90))
			{
				cout << '-';
			}
			else if (((int)str[i - 1] >= 97 && (int)str[i - 1] <= 122) &&
				!((int)str[i + 1] >= 97 && (int)str[i + 1] <= 122))
			{
				cout << '-';
			}
			else if (!((int)str[i - 1] >= 97 && (int)str[i - 1] <= 122) &&
				((int)str[i + 1] >= 97 && (int)str[i + 1] <= 122))
			{
				cout << '-';
			}

			else if (p1 == 3)
			{
				a = (int)str[i + 1] - (int)str[i - 1]-1;
				for (int j = 0;j < a * p2;j++)
				{
					cout << '*';
				}
			}
			else if (p1 == 1)
			{
				if (str[i - 1] >= 97 && str[i - 1] <= 122)
				{
					a = (int)str[i + 1] - (int)str[i - 1] - 1;
					if (p3 == 1)
					{
						for (int j = (int)str[i - 1] + 1;j < (int)str[i + 1];j++)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
					else
					{
						for (int j = (int)str[i + 1] - 1;j > (int)str[i - 1];j--)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
				}
				else if(str[i - 1] >= 65 && str[i - 1] <= 90)
				{
					a = (int)str[i + 1] - (int)str[i - 1] - 1;
					if (p3 == 1)
					{
						for (int j = (int)str[i - 1] + 32 + 1;j < (int)str[i + 1] + 32;j++)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
					else
					{
						for (int j = (int)str[i + 1] + 32 - 1;j > (int)str[i - 1] + 32;j--)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
				}
				else
				{
					a = (int)str[i + 1] - (int)str[i - 1] - 1;
					if (p3 == 1)
					{
						for (int j = (int)str[i - 1] + 1;j < (int)str[i + 1];j++)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
					else
					{
						for (int j = (int)str[i + 1] - 1;j > (int)str[i - 1];j--)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
				}
			}
			else if (p1 == 2)
			{
				if (str[i - 1] >= 97 && str[i - 1] <= 122)
				{
					a = (int)str[i + 1]-32 - (int)str[i - 1]-32 - 1;
					if (p3 == 1)
					{
						for (int j = (int)str[i - 1]-32 + 1;j < (int)str[i + 1]-32;j++)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
					else
					{
						for (int j = (int)str[i + 1]-32 - 1;j > (int)str[i - 1]-32;j--)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
				}
				else if (str[i - 1] >= 65 && str[i - 1] <= 90)
				{
					a = (int)str[i + 1] - (int)str[i - 1] - 1;
					if (p3 == 1)
					{
						for (int j = (int)str[i - 1] + 1;j < (int)str[i + 1];j++)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
					else
					{
						for (int j = (int)str[i + 1] - 1;j > (int)str[i - 1];j--)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
				}
				else
				{
					a = (int)str[i + 1] - (int)str[i - 1] - 1;
					if (p3 == 1)
					{
						for (int j = (int)str[i - 1] + 1;j < (int)str[i + 1];j++)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
					else
					{
						for (int j = (int)str[i + 1] - 1;j > (int)str[i - 1];j--)
						{
							for (int z = 0;z < p2;z++)
							{
								cout << (char)j;
							}
						}
					}
				}
			}
		}
		else
		{
			cout << str[i];
		}
	}
	system("pause");
	return 0;
}

 

 

你可能感兴趣的:(c++,算法,开发语言)