题目链接:P1008 [NOIP1998 普及组] 三连击 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
代码如下:
# include <iostream>
using namespace std;
bool fun(int a, int b, int c)
{
int arr[11];
int ans = 0, t = 3, count = 0;
if((c / 3 != a) || (b / 2 != a))
{
return false;
}
if((c / 3 == a) && (b / 2 == a))
{
while(t--)
{
arr[ans] = (a % 10);
ans++;
a /= 10;
arr[ans] = (b % 10);
ans++;
b /= 10;
arr[ans] = (c % 10);
ans++;
c /= 10;
}
for(int i = 1; i <= 9; i++)
{
for(int j = 0; j < 9; j++)
{
if(i == arr[j])
{
count++;
break;
}
}
}
if(count == 9)
{
return true;
}
else
{
return false;
}
}
}
int main()
{
for(int i = 100; i <= 399; i++)
{
for(int j = 200; j <= 699; j++)
{
for(int k = 300; k <= 999; k++)
{
if(fun(i, j, k))
{
cout<<i<<" "<<j<<" "<<k<<endl;
}
}
}
}
return 0;
}
//
//198 % 10 = 8;
//198 / 10 = 19;
//
//19 % 10 = 9;
这道题考验选手的两个能力,第一个是对于数据范围的把控,第二个是写出一个怎样去把这九个数都不重复且符合1:2:3这个比例。
1311

被折叠的 条评论
为什么被折叠?



