|
|
вернуться в форумTest#5 What's in this test? Results for 0 is 10 For 1..9 is 1..9, it's OK. For 128 is 2222222 Here is alg int n; int e=0; int q=0; cin>>n; if(n==1){cout<<1;cin>>n;return 0;} if(n==0){cout<<10;cin>>n;return 0;} while (n>1) { e=0; if(q==-1)break; for(int i=2;i<=9;i++) {
if((n/i)*i==n) { q=q*10+i; n=n/i; break; } else {if(i==9)e=1;} } if (e==1) q=-1; } cout<<q; cin>>q; return 0; Thanks. Re: Test#5 On input 45 correct answer is 59! In your case answer is 335 Re: Test#5 I didn't give the whole code.. I hate this f*cking excercise.. it is second day I am trying to solve ... now please help me here is the input and output, please be careful to notice something ........ what is wrong here??? first number is my input and the second is output... heeeelp mikael@ubuntu:~/Desktop$ ./xx 1 1 mikael@ubuntu:~/Desktop$ ./xx 0 10 mikael@ubuntu:~/Desktop$ ./xx 2 2 mikael@ubuntu:~/Desktop$ ./xx 3 3 mikael@ubuntu:~/Desktop$ ./xx 4 22 mikael@ubuntu:~/Desktop$ ./xx 5 5 mikael@ubuntu:~/Desktop$ ./xx 6 23 mikael@ubuntu:~/Desktop$ ./xx 8 24 mikael@ubuntu:~/Desktop$ ./xx 9 33 mikael@ubuntu:~/Desktop$ ./xx 10 25 mikael@ubuntu:~/Desktop$ ./xx 20 45 mikael@ubuntu:~/Desktop$ ./xx 25 55 mikael@ubuntu:~/Desktop$ ./xx 30 56 mikael@ubuntu:~/Desktop$ ./xx 45 59 mikael@ubuntu:~/Desktop$ ./xx 60 256 mikael@ubuntu:~/Desktop$ ./xx 105 357 mikael@ubuntu:~/Desktop$ ./xx 108 269 mikael@ubuntu:~/Desktop$ Re: Test#5 for 128 isn't 2222222 , is 882 for(int i=2;i<=9;i++) corect is: for(int i=9;i>=2;i--) becouse 222 is the same product like 8, 33 like 9 Re: Test#5 no for 128 minimal is 288 and not 222222 What's in this test? Results for 0 is 10 For 1..9 is 1..9, it's OK. For 128 is 2222222 Here is alg int n; int e=0; int q=0; cin>>n; if(n==1){cout<<1;cin>>n;return 0;} if(n==0){cout<<10;cin>>n;return 0;} while (n>1) { e=0; if(q==-1)break; for(int i=2;i<=9;i++) {
if((n/i)*i==n) { q=q*10+i; n=n/i; break; } else {if(i==9)e=1;} } if (e==1) q=-1; } cout<<q; cin>>q; return 0; Thanks. Re: Test#5 input 4 output 4 4<22 !! Re: Test#5 sory, but why for 60 is 256? i think it's 160 Re: Test#5 1*6*0 =0; 0 != 60 Edited by author 18.05.2011 20:37 Re: Test#5 Послано ScaV 26 авг 2011 03:02 Edited by author 26.08.2011 03:02 |
|
|