1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | HII guys this is a simple problem...... U can do it as how we divide any number logic:: step 1: take any array for hash for counting how many times any digit is.... i.e int a[10] //for digits 0 to 9 and initilize it with 0 i.e intially count of every digit is zero(0) step 2: after this just check for every i from 0 to 9 if a[i]>0 then inside this just take s=0; for(j=0;j<len;j++) { s=s*10+(str[j]-'0'); if(s>=i) then s=s%i } now after this just check if s==0 then no stored in string is divisible by i th digit else not I HOPE YOU GOT THE LOGIC STILL IF U HAVE ANY PROBLEM U CAN COMMENT BELOW..... MY AC SOLUTION IS ........... #include<bits/stdc++.h> using namespace std; int main() { char str[260]; while(scanf("%s",str)!=EOF) { int a[10]={0}; int len=strlen(str),count=0,i,j; for(i=0;i<len;i++) { int index=str[i]-'0'; a[index]++; } if(a[1]>0) count+=a[1]; for(i=2;i<10;i++) { if(a[i]>0) { int s=0; // printf("dev"); for(j=0;j<len;j++) { s=s*10+(str[j]-'0'); if(s>=i) s%=i; } if(s==0) count+=a[i]; } } printf("%d\n",count); } return 0; } |
Translate
Sunday, 18 January 2015
spoj PUCMM025 solution method-2
Subscribe to:
Post Comments (Atom)
-
HII guys this is totally geometry based problem there is nothing to code just use formula LOGIC::how to find centroid of a polygon u c...
No comments:
Post a Comment