Monday, December 24, 2012

Listen to Santa 2012

Never received a gift from Santa???

Woke up every Christmas morning only to find your bedside empty??

Well here is a chance to change all that and much more!!!

Its a chance to win your best Christmas gift ever ... only you have to earn it...

Come down to Times Square on 25th morning at 10.30 AM sharp .... Be there with your best buddy ... Put your  brains together and solve some simple questions .... find out the clue ... run to the next place ... an event where both your intellectual ability and athleticism will be tested

Come and have lots of fun

  

Wednesday, September 12, 2012

Orient d'Code Problem Statement



You have to place N coins in the form of a stack. A coin can be treated as a circular disk with some radius. You need to take care that when you place a coin on the top of the stack, the radius of the coin should not exceed the radius of the largest coin in the stack by more than 1. Additionally all radii should be positive integers, and the bottom most coin should have its radius as 1. You have to find out in how many ways can you create a stack containing N coins.
Input
First line of the input contains T (T <= 1000) denoting the number of test cases.
T lines follow each containing a single integer N (1 <= N <= 1000) denoting the size of the required stack.
Output
For each case the output should be a single integer representing the number of ways a stack of size N can be created. As the answer can be large, print it modulo 1000000007.
Example
Sample Input
4
1
2
10
15

Sample Output
1
2
115975
382958538



mail your answers to csea.nitwarangal@gmail.com with subject  ODC
You can mail your answer before 3rd October 8pm

Friday, April 27, 2012

Computer Science and Engineering Association Report,Year 2011-2012



This academic year has been a busy and exciting one for CSEA as we conducted various seminars, programmes and contests. I would like to list out our activities in this report with the hope that it serves as a benchmark for future CSEA executive bodies.
Seminars and Workshops Conducted:
1.       Recent trend in Computer Science and Information Technology conducted by team of experts from Infosys and Dr. V.A.Sastri on 5th January,2012
2.       Joomla Workshop- conducted by Sourajeet Bera on 27th March,2012
3.       Maya Workshop- conducted by Sai Shashank on 9th and 10th March,2012
4.       Web Development Workshop- conducted by Gautam Kumar.
Praogrammes Conducted :
1.       Mentorship Program:  In this various small groups of 2nd and 3rd years were mentored by various Final years for a span of 4 months starting from October,2011
2.       Summer Training Guidance Programme(STGP) for 2nd and 3rd years
3.       Game Development  Programme(GDP) conducted by Abhitej John, Raghu Kumar, Somesh Bansal and Sowmya Sree on 29th March,2012 – In this students were shown live demonstrations of how small 2-D games could be made using Java and HTML 5.
4.       Campus Recruitment Training Programme (CRTP)- 14th and 16th April,2012

Contests Conducted:
1.       Mr/Miss CSE – 24th November, 2011
2.       C Contest, conducted on 7th February,2012 – This was the first time that we build our own forum to host MCQs type Computer based tests.
3.       C++ Contest conducted on 21st February , 2012
4.       Java Contest-conducted on 23rd February, 2012
5.       Hack It conducted on 21st March, 2012- It was very successfully conducted by Gautam with great number of participants.
6.       Just Google was conducted on 28th March,2012 - an event which would test your smartness, General awareness, Google Search Knowledge and many more things. An event which easily has the potential of one of the main spot events of Technozion. Hats off to Rohan Sinha for the excellent execution of the event.
7.       ALGOL was conducted on 26th March,2012- amazing event which tests your Algorithmic skill.
8.       Orient d’Code was conducted on 30th March, 2012- The event checked the style of coding along with the output.
9.       Appsurd Idea was conducted from April 1st to April 11th , 2012- Here students had to submit ideas for a new Android Application.
10.   CSE Quiz Contest was conducted on 3rd April, 2012.
11.   Back to the Basics- 11th April,2012, An event which tests must know part of Computer Science. A great exposure to Interview questions.
12.   Programming Contest-conducted From 4th April to 16th April . A series of Problem statement was given. They had to solve all of them. Winner was cumulative topper. 
13.   Test your Wits- 10th April,2012 A Debugging Event

Response from Students:
The best part was that the publicity for all the Events was done properly and hence there was huge turn up for almost all the events

What was new this year:
There were many new events this year, to name a few were Just Google, ALGOL, Coder of the Year Contest, Debugging Contest,Back to the Basics, Hack It and Appsurd Idea.
Contribution to Branch and College: 
1.       Online Programming contests can be held throughout the college. This alone is worth Lakhs. The Forum is ready and is to be inaugurated in the valedictory of CSEA. Kislay Kishore,4th year CSE and Gopi Krishna, 2nd year CSE, was the head in developing this project.

2.       CSEA has also developed an online forum where all MSQ based online tests/contests can be held.

This year we gave very attractive prizes like Tata Photon+ with 5Gb Connection, MTS Connection, 8Gb,4Gb PenDrives, Lenevo Headphones, Dell Wireless mouses, Kasperskey Anti Virus,etc. All these adds as an incentive for participating in all the events coming in the next session. Apart from these prizes each event helped one to showcase his/her skills and knowledge by applying them practically.

Will definitely be very pleased if this year's work is carried forward with the same enthusiasm and we have even greater participations from all the students.

Also I have shared all the pics which I had on the LAN under the name "CSEA 2012 pics". Please download it from there.
Thank you!!

Ravish Roshan
General Secretary,
CSEA

Thursday, April 12, 2012

Programming Contest- Problem Statement 3


Rescue KKR

You have been named CEO of the struggling IPL team,KKR. The owner of KKR has given you the authority to select 3 batsmen with optimal investment of money. You being a complete nerd has no idea of Cricket and also no knowledge about any of the players. So, now you have thought of a very strange idea to select the 3 batsmen. You planned to arrange maximum number of players in their increasing order of price and decreasing order of Batting Average.

Once you got the list of those players in the order. You choose to select the middle 3 players.If the number of players in list is even then select middle two and a player immediate left to them.

Write the program for your selection algorithm.

Given the number of players and their Prices(in million rupees) and Batting Averages, print the total cost needed to be invested.
Input:
First line of input contains T, number of test cases. Following which there are 3T lines, each three consecutive lines describes one test case. First line of each test case contains the total number of players,N. Second line contains the prices of each player in order,Pi and the Third line contains the averages,Ai of each player in the same order. Consider all Ai and Pi as an Integer value.
Output:
For each test cases determine the total cost needed to be invested on the 3 players. In case there are more than 1 list of players, output least investment.
In case the list of players is less than 3, output “I Resign”.
1<=T<=5
3<=N<=200
1<=Pi<100
1<=Ai<100
Example:
Input:
3
10
66 43 7 10 22 12 89 33 21 6
23 45 12 55 67 43 9 22 15 45
8
23 47 91 45 50 90 56 21
77 23 15 50 40 12 37 70
3
33 50 23
54 22 31
Output:
39
151
I Resign



 

Back to the Basics-Questions


1. Code 1:
                ....
                union
                {
                  char a[10];
                  int i;
                } u;
                int *p = (int*) &(u.a[10]);
                *p = 17;
                ....

   Code 2:
                ....
                union
                {
                  char a[10];
                  int i;
                } u;
                int *p = 0;
                *p = 17;
                ....
   Which of the following is true about above two codes when compiled?
               
                a)No errors
                b)Code 1 generates bus error(core dumped)
                  Code 2 generates segmentation fault(core dumped)
                c)Code 1 generates segmentation fault(core dumped)
                  Code 2 generates bus error(core dumped)
                d)Both the codes generate segmentation fault(core dumped)\
Ans: b
Code 1 causes bus error because the array/int Union ensures that character array ‘a’ is
reasonably aligned address for an integer, so ‘a+1’ is definitely not. We then try to store 4 bytes into an address that is aligned only for single byte access.
Code 2 cause segmentation fault as we are dereferencing a pointer with illegal value.

2.  ...
    printf(" %d ",sizeof 'A');
    ...
   What does the above statement print?
Ans: 4
Size of integer used by compiler.(Type promotion).

3.  ...
    line 10: char c[10],*p,i=2;
    ...
                20: c="Computer!!"
 21: printf(" %c %c ",c[8],1[c]);
    ...
    what is the output when compiled? (if any error, mention in which line).
Ans: !o
1[c] is same as c[1] because in both the cases compiler takes them to be *(c+1)
as [] is just a subscript.

4.  ...
    char *p = NULL;
    ...
    printf("%s",p);
   Which of the following options are correct when compiled?
                a)different outputs depending upon compiler
                b)program crashes
                c)No output followed by $
                d)returns garbage value
Ans: a,b
Program crashes as it points to no value and is also dependent upon how NULL is defined in
a Compiler.

*5. Statement 1:P = N * sizeof * q;
   Statement 2:check = sizeof (int) * p;
   Explain statments 1 and 2?(Mention if any errors).
Ans: S1 P= N*size of pointer variable
        S2 size of pointer variable where check must be type int.



*6. Code 1:
                char *cp;
                const char *ccp;
                ccp=cp;  /*Assume some character string is assigned to cp*/
   Code 2;
                char *cp;
                const char *ccp;
                cp=ccp;  /*Assume some character string is assigned to ccp*/

   Which of the following is true when compiled?
                a)both the codes results in a compilation warning
                b)No compilation errors
                c)Code 1:no errors
                  Code 2:results in a compilation error
                d)Code 1:results in a compilation error
                  Code 2:no errors
Ans: c
Left operand must be a qualified type when assignment is done.
Code 1 gives no error or warnings, Code to give warnings as left operand is unqualified.

7. *p.f
   What is it taken to be when compiled?( if error mention it).
Ans: It is taken as *(p.f) as ‘.’ Has higher precedence then ‘*’
So it take f offset from p.

8. char *(*c[10])(int **p);
   Unscramble the above declaration.
Ans: c is an array of 10 pointers to functions returning a pointer to char.
Wher every function must take int **p as an argument.

9. Code 1:
                char **cp;
                const char **ccp;
                ccp=cp;  /*Assume some character string is assigned to cp*/
   Code 2;
                char **cp;
                const char **ccp;
                cp=ccp;  /*Assume some character string is assigned to ccp*/

   Which of the following is true when compiled?
                a)both the codes results in a compilation warning
                b)No compilation errors
                c)Code 1:no errors
                  Code 2:results in a compilation error
                d)Code 1:results in a compilation error
                  Code 2:no errors
Ans: a
Both give compilation warning as
Char **cp and Const char*ccp are unqualified.

10. S1: #define x int[10]
      S2: typedef int x;
  which of the following are true?
                a)In S1 x can be modified
                b)In S2 x can be modified
                c)x can't be modified in S1 and S2
                d)In S2 x can't be modified
Ans: a,d

11.File name Test.c
                #include
                main(int argc,char *argv[])
                {
                  while(--argc > 0)
                  printf("%s%s", *++argv, (argc>1)?" ":"");
                  printf("\n");
                  return 0;
                }
 When the above file is compiled and executed as "$Test Back to the Basics",
 what is the output?( If any error mention it).
Ans: Back to the Basics

*12.In the above program when *++argv is changed to *argv++ what will be the
  output when executed as "$Test Back to the Basics"?
  (if any error mention it).
Ans: Test

**13. char *(*(**arr[][12])())[];
           Explain the meaning of above declaration?
Ans: arr is an array of pointers to pointers to functions returning pointers to an
        array of pointers to char.

14.  #include
     int main()
     {
        int i=1;
        int a=1;
        printf("%d %d %d\n",a,++a,a++);
        printf("%d %d %d\n",i,i++,++i);
        return 0;
     }
     Which of the following can be correct?
                a)3 3 1
                  3 2 2
                b)3 3 1
                  3 2 3
                c)Depends upon compiler
                d)3 3 1
                  3 3 2
Ans: a,b,c,d
Generally it depends upon compiler how the evaluation part is designed.

15. What can be the output of following code?
                ...
                int main(){
                int *p1,**p2;
                double *q1,**q2;
                printf("%d %d ",sizeof(p1),sizeof(p2));
                printf("%d %d",sizeof(q1),sizeof(q2));
                return 0;
                }
                a)2 4 2 4
                b)2 2 2 2
                c)2 4 4 8
                d)4 4 4 4
Ans: b,c
In Linux it is 4 and in turbo it is 2.
16. What is the output when executed?
                int main()
                {
                char c=127;
                printf("%d",++c);
                printf("  %d",++c);
                return 0;}
Ans:127 and 128
As char follow cyclic property.
17. Explain the differnce between them when a(x) is called?
                #define a(x) alter_x(x)
                #define a (x) alter_x(x)
Ans: for 1st statement when a(x) is called it takes alter_x(x) where as for second
(x) alter_x(x) (x) is taken.

18. What will be output if you will compile and execute the following c code?
              void main()
                {
                   printf("%s","alpha" "beta" "gamma");
                }
              a) alpha beta gamma
                b) alpha
                c) compilation error
                d) alphabetagamma

Ans:d
19. What will be output if you will compile and execute the following c code?
              void main()
                {
                int a=-12;
                a=a>>3;
                rintf("%d",a);
                }
              a)-4
                b)compilation error
                c)-2
                d)-96
Ans: c

20.What are the errors in following declaration?
              struct outer{
                int a;
                struct inner{
                char c;
                };
                };
              a)Nesting of structure is not allowed in c.
                b)It is necessary to initialize the member variable.
                c)Inner structure must have name.
                d)Outer structure must have name.
                e)There is not any error.
Ans:c

Wednesday, April 11, 2012

Debugging Contest Questions


NOTE : For each question, unless mentioned in specific, find the errors/bugs and write down the error against the corresponding line. In case the code is correct, write the output. 
Assume all variables have been declared.
Each question carries 1 point. * marked questions carry 2 points.
 
1. This is a program to automate gift delivery on Christmas. Why does it behave in an unexpected manner?
#include < iostream.h >
const char *action[] = {
                    "sleigh to roof",
                    "descend chimney",
                    "fill stockings" };
 
void out( int n )
                    { cout << action[n] << "\n"; }
void santa_do( int a, int b, int c )
                    { out( a ); out( b ); out( c ); }
int main()
                     {
                    int i = 0;
                     santa_do( i++, i++, i++ );
                     return 0;
                    }
 

2.
double read_double (FILE * fp) {
 double d;
 assert(fp != NULL);
 fscanf(fp, " %lf", d);
 return d;
}
The code above contains a common error. Which one of the following describes it?
a. fscanf() will fail to match floating-point numbers not preceded by whitespace.
b. The format specifier %lf indicates that the corresponding argument should be long double rather than double.
c. The call to fscanf() requires a pointer as its last argument.
d. The format specifier %lf is recognized by fprintf() but not by fscanf().
e. d must be initialized prior to usage

3. struct node *nPtr, *sPtr; /* pointers for a linked list. */ 
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)   { 
free(nPtr);
} 
The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work? 
a. It will work correctly since the for loop covers the entire list. 
b. It may fail since each node "nPtr" is freed before its next address can be accessed. 
c. In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next". 
d. This is invalid syntax for freeing memory. 
e. The loop will never end. 

4. void main()    {
                    int realarray[2]={1,2};
                    int *array = &realarray[-1];
                    int i;
                    for(i=0;i<2;i++)
                    {
                        printf("\t%d",*array);
                        array++;
                    }         
       }

5.  #include < iostream.h >
int main()  {     
      extern i;
      printf("%d\n",i);   
       {
            int i=20;
            printf("%d\n",i);
       }
       return 0;
 }

6. #define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
void main()
{
    char *opname = Xstr(OP);
    printf("%s",opname);
}
a. plus                                                                                   b. Compilation Error
c. Runtime Error                                                               d. Linker Error

7. void func()    {
      printf("Testing...Done\n");    }
    int main()     {
      func;
      func();
      getch();
    }
a. Compile-Time Error                                                    b. Testing...Done
c. Testing...DoneTesting...Done                                                d. None of these
8. Which of these operators, when overloaded,  gives an error
a. ->*                                    b.   .*                     c.  ->                      d.   new

9. void main()     {
       int _;
       _=100;
       printf("%d",_);     }
a. 100                                                                                    b. Linker Error
c. Run Time Error                                                              d. Compiler Error             

10. class MyClass
{
    public:
    enum p (a=1,b,c,d,f=32767,y};
};
int main()
 {
    myClass m;
    cout<
    return 0;
}

11. void main()    {
      int choice=2;
      switch(choice)
      {
         default:
            printf("Default1");

         case 1:
            printf("Case1");
            break;

         default:
            printf("Default2");
      }     }
a. Compile-Time Error                                                    b. Default1Case1
c. Default2                                                                          d. Default1

12.  int main()       {
                 const int x;
                 x=128;
                 printf("%d",x);
       }


13. Is the following code valid? If not, what kind or error does it show and why?
main()   {
      main();
}

14. This program should print the sum of numbers from 1 to 5.
 bool f( int n )    {
         n = n + 1;
         if( n < 6 ) return true;
         else return false;
 }
 int main()   {
       int n = 0;
       int sum = 0;
       while( f(n) && n ) sum += n;
       cout<
       return 0;
 }

15. #ifdef something
int some=0;
#endif
main()   {
int thing = 0;
printf("%d %d\n", some ,thing);
}
a.No error             b.Compiler Error           c.Runtime error
If there is any error, specify the reason. If there is no error, write the output :

16. class MyClass {
   int mem;
   void func( int );
};
void (MyClass::*pfunc)(int) = & MyClass::func;
int MyClass::*pmem = & MyClass::mem;
MyClass *p = new MyClass;
p->*pfunc(12);
a. Compiler Error        b. No error         c. Runtime error
If there is any error, specify the reason. If there is no error, write the output :


17. main()  {
      const int size=5;
      int a[size]={1,2,3,4,5};
      int x=2,y=1;
      printf("%d",a[x,y]);
 }
a.Runtime error    b. Compiler error     c.No error
If there is any error, specify the reason. If there is no error, write the output :



18. class Base
{
  public :
    virtual static void myPrint()
    {
       cout<<”Hello World”;
    }
};
void main()
{
  Base b;
  b.myPrint();
}

*19. For this code snippet, identify the conditions under which errors occur/code fails to act as expected.
 #define max 10
int main()
{
char a[max];
int total=1;
char ch;
for(int i=0;i
{
cin>>a[i];
total=total*a[i]; 
cout<<”Do you want to add?\n”;
cin>>ch;
if(ch==’n’)
break;
}
for(int i=0;i
cout<
cout<
return 0;
}

*20.
#define debug(x,y)  x##y
int main()
{
#define f 10
printf("sizeof(f) : %d",sizeof(f));
#define g 'A'
printf("sizeof(g) : %d",sizeof(g));
#undef f 
#define h 'TZ'
#define g '11' 
printf("%d\n", debug(sizeof(f),sizeof(h)));
#define f ‘Hello’
printf(“sizeof(f) : %d\n”,sizeof(f));   }

21. The following code performs certain complex calculations on temperature and displays the annual_delta value. Why does is give unexpected results?
typedef double Temp;
#define Smoke 1.002
#define Mirror 1.001
 
Temp annual_delta( Temp t, double grants, double press_covrg )
{
     return t * Smoke * grants * Mirror * press_covrg;
}
int main()
{
     Temp t = 72.3;      // initial temperature
     int years = 10;
     do  {
          printf( "%d\n", t );
          t = annual_delta( t, 1.002, 1.002 );
         } while( years-- );
     return 0;
 }

22. This is a structure to describe a book. Identify the errors
enum genre { thriller=1, horror, fantasy, mystery };
 struct book
 {
        float price;
        int ISDnumber;
        float length;
        float breadth;
        float height;
        char author[50];
        unsigned isImported : 1;
        enum genre gen:2;
 };
 struct book MyBook;

23. void main() {
const char *a;
char * const b = 0;
const char * const c = 0;
char **d;
char *e;
int i = strlen( b );
a = e;
const char **f=d;
a = b;
e = a; 
}