社区讨论

80分求助大佬!!

P1125[NOIP 2008 提高组] 笨小猴参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lo32pczx
此快照首次捕获于
2023/10/23 23:49
2 年前
此快照最后确认于
2023/10/23 23:49
2 年前
查看原帖
CPP
#include<iostream>
using namespace std;
bool judge(int x)
{
	bool m = true;
	for (int i = 2; i * i < x; i++)
	{
		if (x % i == 0) { m = false; return m; break; }
	}
	return m;
}
int main()
{
	string a; cin >> a;
	int A[100];
	string temp = a;
	int l = temp.length();
	int i ;
	for (i = 0; temp[i] != '\0'; i++)
	{
		A[i] = 1;
		if(temp[i]!='0')
		for (int x = i + 1; x < l; x++)
		{
			if (temp[i] == temp[x]) { A[i]++; temp[x] = '0'; }
		}
	}
	for (int n = 0; n < i; n++)
	{
		for (int j = i - 1; j > n; j--)
		{
			if (A[j] < A[j - 1])
			{
				int temp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = temp;
			}
		}
	}
	int c = A[i - 1] - A[0];
	
	if (c != 0 && c != 1)
	{
		if (judge(c))
		{
			cout << "Lucky Word" << endl;
			cout << c;
		}
		else
			{
				cout << "No Answer" << endl;
				cout << 0;
			}
	}
	if (c == 0 || c == 1)
	{
		cout << "No Answer" << endl;
		cout << 0;
	}
}

回复

3 条回复,欢迎继续交流。

正在加载回复...