解题思路:
思路倒是很简单,我就是通过全排列在做一个筛选从而找出符合题目要求的排列。
注意事项:下面是代码,你们应该都能看得懂
参考代码:
#include<iostream> #include<algorithm> using namespace std; int main() { int s[7]={1,2,3,4,5,6,7}; int a[3],b[3],c[3];//李家为数组 a,王家为数组 b;张家为数组c; do { a[0]=9; b[0]=8; a[1]=s[0]; a[2]=s[1]; b[1]=s[2]; b[2]=s[3]; c[0]=s[4]; c[1]=s[5]; c[2]=s[6]; if((a[0]+a[1]+a[2]==15)&&(b[0]+b[1]+b[2]==15)) { sort(a,a+3); //sort是用来对数组进行从小到大排序 sort(b,b+3); sort(c,c+3); if((a[1]-a[0]!=1)&&(b[1]-b[0]!=1)&&(c[2]-c[1]!=1)&&(c[1]-c[0]!=1)) { if(a[0]==1) cout<<'L'; if(b[0]==1) cout<<'W'; if(c[0]==1) cout<<'Z'; return 0; } } }while(next_permutation(s,s+7)); }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:449 |
【计算两点间的距离】 (C语言代码)浏览:1482 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:407 |
小九九 (C语言描述,不看要求真坑爹)浏览:985 |
Tom数 (C语言代码)浏览:525 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:635 |
拆分位数 (C语言代码)浏览:514 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:455 |
买不到的数目 (C语言代码)浏览:3093 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:595 |