Robert Langdon & Cipher
below given code is for rlcipher spoj or robert langdon & cipher spoj.
logic behind this problem is simple .as number greater then 6 can be expressed in form of multiple of 3 and 4.
let n > 6 then
n = p * 3 + q * 4; p > 0 ,q > 0
eg : 14 = 2*3 + 2*4.
#include<stdio.h> int main() { int t; scanf("%d",&t); int result[7]={-4,-3,-2,-4,-4,-3,-4}; while(t--) { long N; scanf("%ld",&N); int i; long temp; for(i=0;i<N;i++){ scanf("%ld",&temp); if(temp>=0) { if(temp>6) printf("-4 "); else printf("%d ",result[temp]); } else printf("%ld ",temp); } printf("\n"); } return 0; }
No comments:
Post a Comment
Your comment is valuable to us