del Edited by author 06.01.2015 21:37 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 Edited by author 21.06.2014 02:14 Edited by author 21.06.2014 02:14 var a,b,c,d,e,f:integer; begin readln(a,b,c,d,e,f); if ((a+b+c)-(d+e+f))=1 then writeln ('Yes') else if ((d+e+f)-(a+b+c))=1 then writeln ('Yes') else writeln ('No'); end. That's a wrong program. |(a+b+c)-(d+e+f)| always is 1, so your program should always print '1'. #include <iostream> using namespace std; int main() { int a,b,c; cin >> a; b=a-1; c=a+1; if (a%10+(a/10)%10+(a/100)%10==(a/1000)%10+(a/10000)%10+(a/100000)%10 || b%10+(b/10)%10+(b/100)%10==(b/1000)%10+(b/10000)%10+(b/100000)%10 || c%10+(c/10)%10+(c/100)%10==(c/1000)%10+(c/10000)%10+(c/100000)%10) cout << "YES"; else { cout << "NO"; } return 0; } What in test #8? Edited by author 25.07.2013 00:58 Admins, give me some tests, please. i am understand!! need to write std::scanf("%d", &a); insteadd of std::scanf("%i", &a); #include <stdio.h> #include<stdlib.h>
int main() { int arr[5],arr1[5],arr2[5],i,a=0,b=0,n,x=0,y=0; printf("Enter number"); scanf("%d",&n); x=n+1; y=n-1; while(n>0) { for(i=5;i>=0;i--) { arr[i]=n%10; n=n/10; } } a=( arr[0]+arr[1]+arr[2]); b=(arr[3]+arr[4]+arr[5]); // printf("%d%d",a,b); if((a-b==1)||(a-b==-1)) { while(x>0) { for(i=5;i>=0;i--) { arr1[i]=x%10; x=x/10; } } while(y>0) { for(i=5;i>=0;i--) { arr2[i]=y%10; y=y/10; } } if ((arr1[0]+arr1[1]+arr1[2]==arr1[3]+arr1[4]+arr1[5])||(arr2[0]+arr2[1]+arr2[2]==arr2[3]+arr2[4]+arr2[5])) { printf("\nYes");} else { printf("\nNo");} } else { printf("No"); } return 0; } Please, give me some tests, i don't know, what wrong in my program( 725049 No 725870 No 727870 Yes 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 why No?? 725870 + 1 = 725871 (14 != 16) 725870 - 1 = 725869 (14 != 23) Here is my code. Give me some example to test: def sumnum(n): n=str(n) a=0 for i in n: a+=int(i) return a a=int(input()) num=[a+1,a-1] l=1 b='' c='' for a in num: a=(str(a)) b=a[:len((a))//2] c=a[len((a))//2:]
b=sumnum(b) c=sumnum(c) if b==c: print ('Yes') l=0 break if l: print ('No') main() { long n,sumperv=0,sumposled=0,perv,posled; int flag=0; scanf ("%ld",&n); perv=(n+1)/1000; posled=(n+1)%1000; while (perv) { sumperv+=perv%10; perv/=10; } while (posled) { sumposled+=posled%10; posled/=10; } if (sumperv==sumposled) flag=1; perv=(n-1)/1000; posled=(n-1)%1000; sumperv=0; sumposled=0; while (perv) { sumperv+=perv%10; perv/=10; } while (posled) { sumposled+=posled%10; posled/=10; } if (sumperv==sumposled) flag=1;
if (flag==1) printf ("yes"); else printf ("no");
} 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" 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. "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 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 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". 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. why a programe crash? Check your program can handle inputs with leading 0's either the previous or the next ticket is lucky ---- > what does the lucky means ? can anyone give me an example? #include<iostream.h> #include<math.h> #include<stdlib.h> bool prov(char s[10]) { int k1=0,k2=0; k1=s[0]-'0'+s[1]-'0'+s[2]-'0'; k2=s[3]-'0'+s[4]-'0'+s[5]-'0'; if(abs(k2-k1)==1)return true;else return false; } int main() { char s[10],str1[10]; int pr=0,k1,k2; cin>>s; if(prov(s)==true) { ltoa(atol(s)+1,str1,10); k1=str1[0]-'0'+str1[1]-'0'+str1[2]-'0'; k2=str1[3]-'0'+str1[4]-'0'+str1[5]-'0'; if(k1==k2)pr=1; ltoa(atol(s)-1,str1,10); k1=str1[0]-'0'+str1[1]-'0'+str1[2]-'0'; k2=str1[3]-'0'+str1[4]-'0'+str1[5]-'0'; if(k1==k2)pr=1; if(pr==0)cout<<"No";else cout<<"Yes"; }else cout<<"No"; return 0; } Bu naqani maslahat bermayman Edited by author 25.02.2007 11:27 Edited by author 25.02.2007 11:27 445219 da nimaga No 4+4+5<=>2+1+9 yani 13 va 12 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"); } } } |
|