7-16 求符合给定条件的整数集
给定不超过6的正整数A,考虑从A开始的连续4个数字。请输出所有由它们组成的无重复数字的3位数。
输入格式:
输入在一行中给出A。
输出格式:
输出满足条件的的3位数,要求从小到大,每行6个整数。整数间以空格分隔,但行末不能有多余空格。
输入样例:
2
输出样例:
234 235 243 245 253 254
324 325 342 345 352 354
423 425 432 435 452 453
523 524 532 534 542 543
题解:
method one:
#include<iostream>
using namespace std;
main(){
int n,count=0;
cin>>n;
for(int x=n;x<n+4;x++)
{
for(int y=n;y<n+4;y++)
{
for(int z=n;z<n+4;z++)
{
if(x!=y&&x!=z&&y!=z)
{
cout<<x<<y<<z;
count++;
if(count%6!=0)cout<<' '; //行末不能有空格
if(count%6==0)cout<<endl;
}
}
}
}
}
method two:
<