马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
就是在(a,b)区间内区最大的连续合数合数区
输出合数区大小及起始结束#include <iostream>
#include <stack>
using namespace std;
bool isheshu(int);
int main()
{
int a,b;
cin>>a>>b;
int len = 0;
int lastlen = 0;
stack<int>heshuqu;
stack<int>lastheshuqu;
int *p = &a;
while (1)
{
if (isheshu(*p))
{
heshuqu.push(*p);
}
if (!(isheshu(*p)))
{
lastlen = len;
len = heshuqu.size();
if (len > lastlen)
{
for (int i = 0;!heshuqu.empty();i++)
{
lastheshuqu.push(heshuqu.top());
heshuqu.pop();
}
}
}
if (*p == b)
{
break;
}
p++;
}
int begin,finish = heshuqu.top();
cout<<len<<endl;
for (int i = 0;!heshuqu.empty();i++)
{
begin = heshuqu.top();
heshuqu.pop();
}
cout<<begin<<' '<<finish;
return 0;
}
bool isheshu(int a)
{
for (int i = 2;i < a;i++)
{
if (a % i != 0)
{
return 1;
}
}
return 0;
}
能编译
但是输出错误
(NOIP试题预警) |