Escolar Documentos
Profissional Documentos
Cultura Documentos
Input: Output:
2
12 NO
128 YES
main(t,n)
{
if(scanf("%d",&t))
while(scanf("%d",&n),puts(n&n-1?"no":"yes"),--t)
{}
}
main(i)
{
while(~scanf("%d",&i)&&puts(i&i-1?"no":"yes"))
{}
}
CSEHACKERZ 2010
APRIL CODING CONTEST 2010
Input: Output:
2
12 NO
15 YES
main(v,r,t,x)
{
scanf("%d",&t);
while(t--)
{
for(scanf("%d",&v),x=v,r=0;v;r<<=1,r|=v&1,v>>=1)
{}
puts(r-x?"NO":"YES");
}
}
Method 2:
/*for infinite cases, without input T, Using Recursion.*/
int a,t;
main(c,b)
{
c?main(c/2,b*2+c%2):t++/2&&puts(a-b?"NO":"YES"),
~scanf("%d",&a)&&main(a,0);
}
CSEHACKERZ 2010
APRIL CODING CONTEST 2010
Compile and run this. It works fine but how? Actually it’s a very good
example of the preprocessor directive #define and token pasting or
token merging operator ‘##’
Method:
#include"stdio.h"
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf(" hello ");
}
Solution in C:
/* C implementation-swapping */
main(x,y)
{
if(printf("\nEnter a and b:"))
if(scanf("%d %d",&x,&y),printf("\n Before swap: a=%d b=%d",x,y))
if(x=x^y,y=x^y,x=x^y,printf("\n After swap: a=%d b=%d",x,y)){}
}
CSEHACKERZ 2010
APRIL CODING CONTEST 2010
Solution in C++:
/* C++ implementation-swapping */
# include<conio.h>
# include<iostream.h>
void main(int x,int y)
{
if(clrscr(),cout<<"\nEnter a and b:",cin>>x>>y)
if(cout<<"\n Before swap: a="<<x<<" b= "<<y)
if(x=x^y,y=x^y,x=x^y,cout<<"\n After swap: a="<<x<<"
b="<<y,getch())
{}
}
Solution in C:
main(a,b,c,n,f)
{
CSEHACKERZ 2010
APRIL CODING CONTEST 2010
Solution in C++:
/*Fibbonaci */
# include<conio.h>
# include<iostream.h>
/* Factorial */
# include<conio.h>
# include<iostream.h>
CSEHACKERZ 2010
APRIL CODING CONTEST 2010
6. Your task is to add two reversed numbers and output their reversed
sum.
Details:
Of course, the result is not unique because any particular number is a
reversed form of several numbers (e.g. 21 could be 12, 120 or 1200
before reversing). Thus we must assume that no zeros were lost by
reversing (e.g. assume that the original number was 12).
Input:
The input consists of N cases (equal to about 10000). The first line
of the input contains only positive integer N. Then follow the cases.
Each case consists of exactly one line with two positive integers
separated by space. These are the reversed numbers you are to add.
Output:
For each case, print exactly one line containing only one integer -
the reversed sum of two reversed numbers. Omit any leading zeros in
the output.
Example: Table of input & output
Input: Output:
1
24 1 34
/*
*/
CSEHACKERZ 2010
APRIL CODING CONTEST 2010
Solution:
int c[10000],i=0;
main(a,b,t)
{
int x,y,*sum,j=0;
scanf("%d",&t);
while((t--)>0)
{
scanf("%d %d",&a,&b);
CSEHACKERZ 2010