紧急问题谢谢,100分,在线等~~~

conan0267 2004-10-25 09:39:25
1-9,凑成1:2:3,3三个3位数
显示出所有的可能
...全文
343 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
dzy1982 2004-10-26
  • 打赏
  • 举报
回复
靠!1--9不能重复的。
ToWeightAnchor 2004-10-25
  • 打赏
  • 举报
回复
麻烦楼主说清楚一下。
ningliang 2004-10-25
  • 打赏
  • 举报
回复
大家注意这些数字当中是不能含有 0的!!!!
lamputa_lito 2004-10-25
  • 打赏
  • 举报
回复
如果真如jitian81411(太阳)所理解的,那么这道题就是太简单了,如果是我所猜想的 那样,这道题目好似无解。看来要问楼主的意思是什么了。
lamputa_lito 2004-10-25
  • 打赏
  • 举报
回复
TO:jitian81411(太阳)
你有无理解题意,题目的意思是说1~9个数,分成三份,每份三个数字(这些数字是不可以重复的,你的什么222,333的,明显不行嘛)
xuzheng318 2004-10-25
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

int main()
{
for(int i = 100; i < 1000 ; i++)
{
for(int j = 100; j < 1000; j++)
{
if( j != (i * 2))
{
continue;
}
for(int k = 100; k < 1000; k++)
{
if(i * 3 == k)
{
cout << i << "\t" << j << "\t" << k << endl;
}
}
}
}

system ("pause");
return 0;
}
carylin 2004-10-25
  • 打赏
  • 举报
回复
to jitian81411(太阳)

佩服!
jitian81411 2004-10-25
  • 打赏
  • 举报
回复
要从效率出发的话就没有必要做3个循环了,也就是要一个就可以了,具体程序如下:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
for(int a=100;a<=333;a++){
cout<<a<<'\t'<<(a*2)<<'\t'<<(a*3)<<endl;
}
system("pause");
return 0;
}
结果完全一样,并且也符合楼主的要求。
avalonBBS 2004-10-25
  • 打赏
  • 举报
回复
不好意思,刚才误解题意了:(
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
for(int a=100;a<=999;a++){
for(int b=200;b<=999;b++){
if(b!= a*2)continue;
for(int c=300;c<=999;c++){
if(c==a*3 && b==a*2)
cout<<a<<'\t'<<b<<'\t'<<c<<endl;
}
}
}
system("pause");
return 0;
}
/////////////////////////////////////////////////////////////////
100 200 300
101 202 303
102 204 306
103 206 309
104 208 312
105 210 315
106 212 318
107 214 321
108 216 324
109 218 327
110 220 330
111 222 333
112 224 336
113 226 339
114 228 342
115 230 345
116 232 348
117 234 351
118 236 354
119 238 357
120 240 360
121 242 363
122 244 366
123 246 369
124 248 372
125 250 375
126 252 378
127 254 381
128 256 384
129 258 387
130 260 390
131 262 393
132 264 396
133 266 399
134 268 402
135 270 405
136 272 408
137 274 411
138 276 414
139 278 417
140 280 420
141 282 423
142 284 426
143 286 429
144 288 432
145 290 435
146 292 438
147 294 441
148 296 444
149 298 447
150 300 450
151 302 453
152 304 456
153 306 459
154 308 462
155 310 465
156 312 468
157 314 471
158 316 474
159 318 477
160 320 480
161 322 483
162 324 486
163 326 489
164 328 492
165 330 495
166 332 498
167 334 501
168 336 504
169 338 507
170 340 510
171 342 513
172 344 516
173 346 519
174 348 522
175 350 525
176 352 528
177 354 531
178 356 534
179 358 537
180 360 540
181 362 543
182 364 546
183 366 549
184 368 552
185 370 555
186 372 558
187 374 561
188 376 564
189 378 567
190 380 570
191 382 573
192 384 576
193 386 579
194 388 582
195 390 585
196 392 588
197 394 591
198 396 594
199 398 597
200 400 600
201 402 603
202 404 606
203 406 609
204 408 612
205 410 615
206 412 618
207 414 621
208 416 624
209 418 627
210 420 630
211 422 633
212 424 636
213 426 639
214 428 642
215 430 645
216 432 648
217 434 651
218 436 654
219 438 657
220 440 660
221 442 663
222 444 666
223 446 669
224 448 672
225 450 675
226 452 678
227 454 681
228 456 684
229 458 687
230 460 690
231 462 693
232 464 696
233 466 699
234 468 702
235 470 705
236 472 708
237 474 711
238 476 714
239 478 717
240 480 720
241 482 723
242 484 726
243 486 729
244 488 732
245 490 735
246 492 738
247 494 741
248 496 744
249 498 747
250 500 750
251 502 753
252 504 756
253 506 759
254 508 762
255 510 765
256 512 768
257 514 771
258 516 774
259 518 777
260 520 780
261 522 783
262 524 786
263 526 789
264 528 792
265 530 795
266 532 798
267 534 801
268 536 804
269 538 807
270 540 810
271 542 813
272 544 816
273 546 819
274 548 822
275 550 825
276 552 828
277 554 831
278 556 834
279 558 837
280 560 840
281 562 843
282 564 846
283 566 849
284 568 852
285 570 855
286 572 858
287 574 861
288 576 864
289 578 867
290 580 870
291 582 873
292 584 876
293 586 879
294 588 882
295 590 885
296 592 888
297 594 891
298 596 894
299 598 897
300 600 900
301 602 903
302 604 906
303 606 909
304 608 912
305 610 915
306 612 918
307 614 921
308 616 924
309 618 927
310 620 930
311 622 933
312 624 936
313 626 939
314 628 942
315 630 945
316 632 948
317 634 951
318 636 954
319 638 957
320 640 960
321 642 963
322 644 966
323 646 969
324 648 972
325 650 975
326 652 978
327 654 981
328 656 984
329 658 987
330 660 990
331 662 993
332 664 996
333 666 999
请按任意键继续 . . .
newegg2002 2004-10-25
  • 打赏
  • 举报
回复
穷举法这样写:

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{

for(int i=1;i<10;++i)
for(int j=i;j<10;++j)
for(int k=j;k<10;++k)
{

if(!((i+j+k)%6)) //如果它们的和不能被6整除的话.是不会形成这样的数的.
{
if((i*6 == j*3)&&(j*3 ==k*2)) //进一步判断,,
cout<<i<<j<<k<<endl;
}

}
system("pause");
}
再想一下好的算法吧..
carylin 2004-10-25
  • 打赏
  • 举报
回复
楼主看看这样行不。
#include <iostream>
using namespace std;

int main()
{
for(int i = 100; i < 1000 ; i++)
{
for(int j = 100; j < 1000; j++)
{
if( j != (i * 2))
{
continue;
}
for(int k = 100; k < 1000; k++)
{
if(i * 3 == k)
{
cout << i << "\t" << j << "\t" << k << endl;
}
}
}
}

system ("pause");
return 0;
}
carylin 2004-10-25
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

int main()
{
for(int i = 100; i < 1000 ; i++)
{
for(int j = 100; j < 1000; j++)
{
if( j != (i * 2))
{
continue;
}
for(int k = 100; k < 1000; k++)
{
if(i * 3 == k)
{
cout << i << "\t" << j << "\t" << k << endl;
}
}
}
}

system ("pause");
return 0;
}
avalonBBS 2004-10-25
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;

int main(void)
{
int a,b,c;
for(a=1;a<=9;a++){
for(b=1;b<=9;b++){
if( b!= (a*2))continue;
for(c=1;c<=9;c++){
if(a*2==b && a*3==c)
cout<<"a="<<a<<"b="<<b<<"c="<<c<<endl;
}
}
}
return 0;
}
CSmaz_hand 2004-10-25
  • 打赏
  • 举报
回复
mark
carylin 2004-10-25
  • 打赏
  • 举报
回复
强烈建议楼主不给 xuzheng318(forever C++) 分。

他的代码是拷贝我的。这人没道德!1
carylin 2004-10-25
  • 打赏
  • 举报
回复
to: xuzheng318(forever C++)
你这样不好吧!!!

把我的代码一字不拉的拷下来发上去!
ningliang 2004-10-25
  • 打赏
  • 举报
回复
用一个循环来判断有111(第一个满足条件的数)到333(满足条件的最大数)
之间的数,如果这些数不含零就输出。
# include <stdio.h>
# include <stdlib.h>

bool Whe_Proper(int i);//关键部分,判断这个数据是否合乎要求

void main()
{
register int nums = 111;//将数据定义在寄存器中,并初始化为111,第一个符合要求的三位数

printf("the numbers are as follows :\n");

for(nums;nums <= 333;nums++){

if(Whe_Proper(nums)) {
printf("%d % d % d\n",nums,2*nums,3*nums);//如果满足条件就将这组数输出;
}

}

return;
}

bool Whe_Proper(int i)
{
int tempI = i%10;
int temp2I = (2*i)%10;
int temp3I = (3*i)%10;

if(tempI == 0 || temp2I == 0){ //如果个位数为0或者5则有i或者2*i不符合题目要求
return false;
}else if((i-tempI)%100 == 0 ||(2*i-temp2I)%100 == 0||(3*i-temp3I)%100 == 0){
return false;
}
return true;
}
the numbers are as follows :
111 222 333
112 224 336
113 226 339
114 228 342
116 232 348
117 234 351
118 236 354
119 238 357
121 242 363
122 244 366
123 246 369
124 248 372
126 252 378
127 254 381
128 256 384
129 258 387
131 262 393
132 264 396
133 266 399
137 274 411
138 276 414
139 278 417
141 282 423
142 284 426
143 286 429
144 288 432
146 292 438
147 294 441
148 296 444
149 298 447
156 312 468
157 314 471
158 316 474
159 318 477
161 322 483
162 324 486
163 326 489
164 328 492
166 332 498
171 342 513
172 344 516
173 346 519
174 348 522
176 352 528
177 354 531
178 356 534
179 358 537
181 362 543
182 364 546
183 366 549
184 368 552
186 372 558
187 374 561
188 376 564
189 378 567
191 382 573
192 384 576
193 386 579
194 388 582
196 392 588
197 394 591
198 396 594
199 398 597
211 422 633
212 424 636
213 426 639
214 428 642
216 432 648
217 434 651
218 436 654
219 438 657
221 442 663
222 444 666
223 446 669
224 448 672
226 452 678
227 454 681
228 456 684
229 458 687
231 462 693
232 464 696
233 466 699
237 474 711
238 476 714
239 478 717
241 482 723
242 484 726
243 486 729
244 488 732
246 492 738
247 494 741
248 496 744
249 498 747
256 512 768
257 514 771
258 516 774
259 518 777
261 522 783
262 524 786
263 526 789
264 528 792
266 532 798
271 542 813
272 544 816
273 546 819
274 548 822
276 552 828
277 554 831
278 556 834
279 558 837
281 562 843
282 564 846
283 566 849
284 568 852
286 572 858
287 574 861
288 576 864
289 578 867
291 582 873
292 584 876
293 586 879
294 588 882
296 592 888
297 594 891
298 596 894
299 598 897
311 622 933
312 624 936
313 626 939
314 628 942
316 632 948
317 634 951
318 636 954
319 638 957
321 642 963
322 644 966
323 646 969
324 648 972
326 652 978
327 654 981
328 656 984
329 658 987
331 662 993
332 664 996
333 666 999
greenteanet 2004-10-25
  • 打赏
  • 举报
回复
可以按照生成组合的算法解决啊。这样子也就可以先生成一个组合,然后生成一个比前面的组合更加大的组合,在用循环就可以了。
liujingfu123 2004-10-25
  • 打赏
  • 举报
回复
应该是1-9这些数字不重复的组合吧!
lujianping 2004-10-25
  • 打赏
  • 举报
回复
版主,100分拿来


#include "stdio.h"
#include "string.h"

#define M_SWAP(x,y,type) {type sap; sap = x ; x = y; y = sap;}

#define TRUE (1)
#define FALSE (0)

int GetNextGroup(int *piSrc,int iIndex,int nMax)
{
int i;
int iBack;

for ( i = iIndex + 1 ; i < nMax ; i ++ )
{
if ( piSrc[i] > piSrc[iIndex] )
{
M_SWAP(piSrc[i],piSrc[iIndex] ,int ) ;
return TRUE;
}
}
if ( iIndex == 0 )
return FALSE;

//最后一个已经无法改变了
iBack = piSrc[iIndex] ;
for ( i = 0 ; i < nMax - iIndex ; i ++ )
{
piSrc[iIndex + i] = piSrc[iIndex + i + 1] ;
}
piSrc[nMax-1] = iBack ;

return GetNextGroup( piSrc,--iIndex,nMax) ;
}

int main(int argc, char* argv[])
{
int piSrc[9] = {1,2,3,4,5,6,7,8,9};

do{
printf("Get Result:" ) ;
printf("%d,%d%d,%d%d%d\n",piSrc[0],piSrc[1],piSrc[2],
piSrc[3],piSrc[4],piSrc[5] ) ;
}
while( GetNextGroup(piSrc,5,9 ) == TRUE );
return 0;
}

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧