萌新求助,怎么答案是错误的呢,没检查出问题:(

P1008 [NOIP1998 普及组] 三连击

调整一下输出顺序就好了,第22行改成: `a=i*100+j*10+k;`
by 杜都督 @ 2024-02-06 22:05:08


@[杜都督](/user/39279) 谢谢大佬,问题解决了。 但是我有个疑问,为什么只是修改一下计算的顺序就可以了呢,感觉没差别啊
by baibaidebai @ 2024-02-15 18:23:35


@[baibaidebai](/user/1153682) 因为 ## 输出格式 若干行,每行 $3$ 个数字。按照每行第 $1$ 个数字 ***升序*** 排列。 如果按照你原来的写法就是乱序排列了
by 杜都督 @ 2024-02-16 02:18:01


@[baibaidebai](/user/1153682) 反正我是直接算的
by AC_710GD @ 2024-02-16 22:44:00


@[杜都督](/user/39279) 哦哦哦,明白了! 简直醍醐灌顶,感谢
by baibaidebai @ 2024-02-20 14:38:34


```cpp #include<iostream> #include<algorithm> using namespace std; int main() { int A[] = { 1,2,3,4,5,6,7,8,9 }; int x1, x2, x3; do { x1 = A[0] * 100 + A[1] * 10 + A[2]; x2 = A[3] * 100 + A[4] * 10 + A[5]; x3 = A[6] * 100 + A[7] * 10 + A[8]; if (x1 * 2 == x2 && x2 * 3 == x3 * 2 && x1 * 3 == x3) { cout << x1 <<" "<< x2 <<" "<< x3 << endl; } } while (next_permutation(A,A+9)); return 0; }
by swuster27 @ 2024-02-24 14:05:05


@[baibaidebai](/user/1153682) ``` #include<iostream> using namespace std; int n[9]={0,0,0,0,0,0,0,0,0}; int sum=0; bool notSame(int a,int b,int c){ sum=0; n[0]=a/100;n[1]=a/10%10;n[2]=a%10; n[3]=b/100;n[4]=b/10%10;n[5]=b%10; n[6]=c/100;n[7]=c/10%10;n[8]=c%10; for(int i=0;i<9;i++)for(int j=0;j<9;j++)if(n[i]==n[j]&&i!=j||n[i]==0)return false; return true; } int main() { int a,b,c; for(a=100;a<=333;a++){ b=2*a;c=a*3; if(notSame(a,b,c))cout<<a<<" "<<b<<" "<<c<<" "<<endl; } return 0; } ```
by Charlie509 @ 2024-04-20 15:54:38


|