Show all threads Hide all threads Show all messages Hide all messages |
Page 2 |
GDE OWIBKA ? (JAVA) | shaihin | 1493. One Step from Happiness | 13 Jan 2020 16:53 | 4 |
import java.util.*; public class LuckyNumber{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int x = in.nextInt(); int a1,a2,a3,b1,b2,b3; a1 = x/100000; a2 = (x/10000)%10; a3 = (x/1000)%10; b1 = (x/100)%10; b2 = (x/10)%10; b3 = x%10; if((a1+a2+a3) == (b1+b2+b3)) System.out.println("Lucky Number"); else if(a1+a2+a3-(b1+b2+b3)>1 ||(b1+b2+b3)-(a1+a2+a3)>1) { System.out.println("prostoi bilet"); } else System.out.println("Lucky Number budet sleduwii ili prediduwi bilet"); } } You should output "Yes" or "No" and nothing else |
Can you give me solution? | bekmyrat | 1493. One Step from Happiness | 2 Nov 2012 21:06 | 2 |
Add '1' to the input number and see if it's lucky, i.e. if the sum of the first 3 digits is the same as the sum of the second 3 digits of the newly formed number. Subtract '1' from the input number and check the same. Output 'Yes' if the newly formed number satisfies the condition, and 'No' otherwise. |
the means of luck | HaiyangZheng | 1493. One Step from Happiness | 3 Oct 2012 20:27 | 1 |
"either the previous or the next ticket is lucky." and "one step from happiness" lucky means: previous OR next, sum of first three digits EQUAL sum of last three digits. Edited by author 03.10.2012 20:54 |
Yordam! Pomogite! Help! | Hamdam_TUIT | 1493. One Step from Happiness | 14 Oct 2014 12:41 | 4 |
Test #01 куда тут ошибка помогите пожалуйста #include <iostream> using namespace std; int main () { short int A[6]; signed int s=0,s2=0; for (int i=0;i<6;i++) cin>>A[i]; for (int i=0;i<3;i++) s=s+A[i]; for (int i=5;i>=3;i--) s2=s2+A[i];
if ((s-s2==-1) || (s-s2==1 && A[5]!=9)) cout<<"Yes";
else cout<<"No"; //system ("pause");
return 0;
} Edited by author 22.06.2012 19:44 masalan int s; bo'lsa, cin>>S qilib o'qitish kerak . OK masalan int s; bo'lsa, cin>>S qilib o'qitish kerak . OK |
No subject | Saba [IFG] | 1493. One Step from Happiness | 5 Mar 2012 19:07 | 1 |
either the previous or the next ticket is lucky ---- > what does the lucky means ? can anyone give me an example? |
Crash | HSTU_hacker | 1493. One Step from Happiness | 1 Apr 2012 13:39 | 3 |
Crash HSTU_hacker 27 Feb 2012 02:10 Check your program can handle inputs with leading 0's |
ADMINS: Possible missing definition | Amndeep Singh Mann | 1493. One Step from Happiness | 24 Apr 2012 06:48 | 3 |
Now, I could be saying something stupid here. But I think we're missing a definition of what happens at the topmost boundary. Say our number is 999,999, if you subtract one, you don't get a lucky number, but if you add one, then what happens? The problem said that it was going to be a 6 digit number at all times, but if you add one, it becomes a seven digit number, so does this case never occur? And if it does, then does the lucky number formula apply only to the last 6 digits of the number? You are right. In fact all the tram tickets have exactly 6 digits, so ticket 1000000 doesn't exist. I have added this phrase to the hint. It doesn't really matter, because the problem definition says the sum of the first 3 and last 3 digits differs by one. 999,998 fits this definition, but 999,999 does not. |
help plz | Erwin Saul Serrudo Condori | 1493. One Step from Happiness | 17 Nov 2011 00:21 | 1 |
help plz Erwin Saul Serrudo Condori 17 Nov 2011 00:21 this is my code, but wa in test 1, why? what is the test 1, thanks sorry my english is very poor import java.io.*; import java.util.*; public class Main{ static int sum(int n) { int sum=n%10+(n/10)%10+(n/100)%10; return sum; }
static boolean solve(String n) { String ant=n.substring(0,3); String post=n.substring(3,6); if(ant.compareTo(post)==0) return true; else {
int antn=Integer.parseInt(ant); int postn=Integer.parseInt(post); int a; int b; int c; int d; if(postn+1>999) { a=antn+1; b=0; } else { a=antn; b=postn+1; } if(postn-1<0) { c=antn-1; d=999; } else { c=antn; d=postn-1; } a=sum(a); b=sum(b); c=sum(c); d=sum(d);
if(a==b||c==d) return true; else return false; } }
public static void main (String args[]) { Scanner in=new Scanner(System.in); String n; while(in.hasNext()) { n=in.next(); if(solve(n)) System.out.println("YES"); else System.out.println("NO"); } } } |
AC Pascal | Dima | 1493. One Step from Happiness | 9 Nov 2011 15:45 | 1 |
var a,b,c,d,e,f,g,r,v:integer; begin while(true)do begin read(a); r:=a+1; v:=a-1; b:=r mod 10; c:=(r mod 100) div 10; d:=(r mod 1000) div 100; e:=r div 100000; f:=(r div 10000)mod 10; g:=(r div 1000)mod 10; if (b+c+d=e+f+g) then begin write('Yes') ; break;end; b:=v mod 10; c:=(v mod 100) div 10; d:=(v mod 1000) div 100; e:=v div 100000; f:=(v div 10000)mod 10; g:=(v div 1000)mod 10; if (b+c+d=e+f+g) then write('Yes') else write('No'); break; end; end. Edited by author 09.11.2011 15:46 |
What is test #6 ??? | bigtik | 1493. One Step from Happiness | 17 Oct 2011 04:51 | 1 |
Can anyone tell me what the test #6 is? In my opinion the solution is correct, but it gives wa on test #6... And also, if the number is 999999 it should take as the next number 000000 or it should consider, that there is no next number and print "No"??? The same for 000000? |
WA test 1 | Jumabek_Alihonov | 1493. One Step from Happiness | 18 Sep 2011 16:36 | 1 |
this is my solution #include<iostream> using namespace std; int main() { int n,a,b,c,d,s1=0,s2=0; cin>>n; a=n;
n=a+1; s1+=n%10;n=n/10; s1+=n%10; n=n/10; s1+=n%10;n=n/10;
s2+=n%10;n=n/10; s2+=n%10;n=n/10; s2+=n%10;n=n/10; if(s1==s2)b=1; n=a-1;s1=0;s2=0; if(n==1) cout<<"YES"; else { s1+=n%10;n=n/10; s1+=n%10; n=n/10; s1+=n%10;n=n/10;
s2+=n%10;n=n/10; s2+=n%10;n=n/10; s2+=n%10;n=n/10; if(s1==s2)b=1; } if(b==1)cout<<"YES"; else cout<<"NO"; } |
445219 No 4+4+5=13 2+1+9=12 <<<---- Why ANSWer is No ? ? ? | David Tvildiani[Tbilisi SU] | 1493. One Step from Happiness | 22 Jul 2012 18:13 | 7 |
715068 Yes 7+1+5=13 0+6+8=14 445219 No 4+4+5=13 2+1+9=12 <<<---- Why ANSWer is No ? ? ? 012200 Yes 0+1+2=3 2+0+0=2 WTF ? Edited by author 25.07.2011 00:19 Edited by author 25.07.2011 02:11 because next ticket is "445220" because next ticket is "445220" wth! Why is that so? because next ticket is "445220" wth! Why is that so? Yes, Sure!!! Ticket is: 715068 7+1+5=13 0+6+8=14 Next ticket is: 715069 7+1+5=13 0+6+9=15 Why answer is "Yes"? it is next, but before was 715067 7+1+5=13 and 0+6+7=13 |
HELP TO SOLVE THIS PROBLEM IN C++ PLEASE | BORIS (YSU) | 1493. One Step from Happiness | 7 Jul 2011 22:33 | 2 |
Edited by author 17.10.2010 20:13 you can use sprintf, and problem becomes easier |
Hint | Wyand | 1493. One Step from Happiness | 28 Aug 2010 21:26 | 2 |
Hint Wyand 26 Apr 2010 21:08 Mind the tests 000000 and 999999 999999+1 and 000000-1 don't belong to the definition of ticket Re: Hint TSU: IVIuxianski 28 Aug 2010 21:26 i wonder, which part of 999999 or 000000 is greater or less by 1 than the other one? |
What is wrong?ADMINS?Why WA on test #6 | George Skhirtladze | 1493. One Step from Happiness | 5 Feb 2013 00:07 | 2 |
var a:array[1..6]of integer; i:integer; g:char; s:string; begin read(s); for i:=1 to 6 do val(s[i],a[i],g); if (a[6]<>9) and ((a[1]+a[2]+a[3]=a[4]+a[5]+a[6]+1)or (a[1]+a[2]+a[3]=a[4]+a[5]+a[6]-1))then writeln('Yes') else writeln('No'); end. try this case: 550009 answer should be "No" |
what's wrong | dheman | 1493. One Step from Happiness | 26 Feb 2010 02:47 | 2 |
my code is #include<stdio.h> #include<string.h> int main() { char a[10]; while(scanf("%s",a)==1) { long int s1=0,s2=0; long int len = strlen(a); for(long int i=0;i<len;i++) { if(i<3) s1 = s1 + (a[i]-'0'); else s2 = s2 + (a[i] - '0'); } long int sub = s1 - s2;
if(sub ==1 || sub== -1) { if(sub==1) { long int add = (a[len-1]-'0')+1; if(add>9) { printf("No\n"); } else printf("Yes\n"); } else if(sub == -1) { if(a[len-1]<1) printf("No\n"); else printf("Yes\n"); } } else printf("No\n"); } return 0; } i don't know where is my problem. please help me. opps. sorry .. i found my mistake.. |
Why it is wrong? | GulfStream | 1493. One Step from Happiness | 6 Nov 2009 01:58 | 1 |
Edited by author 06.11.2009 02:55 |
What's the meaning of this problem? | beef money | 1493. One Step from Happiness | 9 Jul 2012 02:07 | 2 |
I couldn't understand the statements. You're supposed to see if either the next or previous tickets were lucky. For example, if it was 000001, then the previous ticket (000000) would have been lucky and you should output "Yes". |
Why Test_1 Failed? | Alireza_Keshmiri | 1493. One Step from Happiness | 19 Feb 2009 10:24 | 3 |
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int[] ints = ReadInts(in); int first = ints[0] + ints[1] + ints[2]; int second = ints[3] + ints[4] + ((ints[5] == 9) ? 1 : ints[5] + 1); int third = ints[3] + ints[4] + ((ints[5] == 0) ? 8 : ints[5] - 1); System.out.println((first == second) || (first == third) ? "YES" : "NO"); } public static int[] ReadInts(BufferedReader in) throws IOException { int[] result = new int[6]; String input = in.readLine(); for (int i = 0; i < input.length(); i++) { result[i]=Integer.parseInt(input.substring(i, i + 1)); } return result; } } Maybe Yes/No instread of YES/NO? yap :) thanks Edited by author 19.02.2009 10:24 Edited by author 19.02.2009 10:24 |
Tests | MOPDOBOPOT | 1493. One Step from Happiness | 15 May 2013 17:31 | 7 |
Tests MOPDOBOPOT 18 Jan 2009 22:15 Please, give me some tests, i don't know, what wrong in my program( 725049 No 725870 No 727870 Yes Tests MOPDOBOPOT 16 Feb 2009 19:38 My solution: *** program lam; var st,s1,s2,ins: string; e1,e2,k,n2,n1,e,z,q,i: integer; begin readln(st); z:=0; if st[1]='0' then begin q:=1; for i:=2 to 5 do begin if st[i]='0' then inc(q); if st[i]<>'0' then break; end; end; val(st,e,k); n1:=e+1; n2:=e-1; str(n1,s1); str(n2,s2); if q=1 then begin ins:='0'; insert(ins,s1,1); end; if q=2 then begin ins:='00'; insert(ins,s1,1); end; if q=3 then begin ins:='000'; insert(ins,s1,1); end; if q=4 then begin ins:='0000'; insert(ins,s1,1); end; if q=5 then begin ins:='00000'; insert(ins,s1,1); end; if q=1 then begin ins:='0'; insert(ins,s2,1); end; if q=2 then begin ins:='00'; insert(ins,s2,1); end; if q=3 then begin ins:='000'; insert(ins,s2,1); end; if q=4 then begin ins:='0000'; insert(ins,s2,1); end; if q=5 then begin ins:='00000'; insert(ins,s2,1); end; val(copy(s1,1,3),e1,k); val(copy(s1,4,3),e2,k); if (e1 mod 10)+((e1 mod 100) div 10)+(e1 div 100)=(e2 mod 10)+((e2 mod 100) div 10)+(e2 div 100) then z:=1; val(copy(s2,1,3),e1,k); val(copy(s2,4,3),e2,k); if (e1 mod 10)+((e1 mod 100) div 10)+(e1 div 100)=(e2 mod 10)+((e2 mod 100) div 10)+(e2 div 100) then z:=1; if z=1 then writeln('YES') else writeln('NO'); end. *** очень большое и глупое решение, гораздо проще вот так: function prov(n:longint):integer; var a1,a2,a3,b1,b2,b3:integer; begin a1:=n div 100000; a2:=n div 10000 mod 10; a3:=n div 1000 mod 10; b1:=n div 100 mod 10; b2:=n div 10 mod 10; b3:=n mod 10; if b1+b2+b3=a1+a2+a3 then prov:=1 else prov:=2; end; var n,n1,n2:longint; begin read(n); n1:=n+1; n2:=n-1; if (prov(n1)=1)or(prov(n2)=1) then writeln('Yes') else writeln('No'); end. sorry for russian. P.S. Time 0.031 Memory 118 725870 + 1 = 725871 (14 != 16) 725870 - 1 = 725869 (14 != 23) Re: Tests Muzaffardjan Karaev 15 May 2013 17:31 |