locked
Its time to share RRS feed

  • Question

  • hey friends ,,,,,,,Come forward with ur quiz question and answer if u have done it .........
    Wednesday, March 21, 2007 2:37 PM

Answers

  •  Harshil_Patel_03b5f2 wrote:
    NCE College of Technology is the popular college in the city. In their library department they were facing some problems in issuing and returning the book. They decided to make some changes in the books order and their unique number. So they are in need of developing new system for avoiding their problems. They will give the existing book number; you have to give the new number such a way that, a new book numbers the minimal next one with the same sum of digits and the change the alphabet according to sum and give the new book numbers.
    # Constraints: The input is a combination of one alphabet and numerical values
    # The output is INVALID if there is more than one alphabet or no alphabet, the output combinations should be greater than the input combinations and the output does not consist equal number of digits as in the input


    Example:
    Input1 = J0921
    Ouput1 = M0930. As the sum of the digits in the input is 12 the output is the next nearest digit whose sum is 12
    The alphabet is obtained in a such a way that J(0+9+2+1)=J(12)
    J(1+2)=J(3)=J+3=M. Therefore the output is M0930.
    Input2 = 67867
    Ouput2 = INVALID

    Input3 = U992
    Ouput3 = INVALID As there is no combinations greater than the input.

    Input4 = U0992
    Ouput4 = W1199

    For C solutions
    Header File : BookNumber.h
    Function Name : char* getNewNumber(char* number)
    Directory Name : booknumber
    File Name : booknumber.c
    For C++ solutions
    Header File : BookNumber.h
    Class Name : library
    Function Name : char* getNewNumber(char* number)
    Directory Name : booknumber
    FileName : booknumber.cpp

    General Instructions:
    *

    The directory names, file / class names, functions, method signatures, header files to be used are mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods.
    *

    First add the directory in the Main Program Directory and then add the particular file in that directory. Do not forget to mention the file extension, either .c or .cpp as the case maybe.





    #include"BookNumber.h"
    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
    #include<math.h>
    int cntalpha(char str[]) {
        int cnt=0,i;
        for(i=0 ; strIdea ; i++)
            if(isalpha(strIdea)) cnt++;
        return cnt;
    }
    int sumofdig(long num) {
        int sum=0;
        while(num>0)
            sum+=(num%10),num/=10;
        return sum;
    }
    char outs[80]={0};
    char* getNewNumber(char* number) {
        char ch, outch;    int numlen=0, flag, sumd=0; long i=0,num, ansnum;
        if(cntalpha(number)!=1)
            return "INVALID";
        else {
            ch=number[0];
            numlen=strlen(number)-1;
            if(!isalpha(ch)) return "INVALID";
            sscanf(number,"%c%ld",&ch,&num);
            sumd=sumofdig(num);
            for(flag=0,i=(long)num+1 ; i<(int)pow(10,numlen)-1 ; i++) {
                if(sumofdig(i)==sumd) {
                    ansnum=i;
                    flag=1;
                    break;
                }
            }
            if(flag==0) return "INVALID";
            ch+=(sumofdig(sumofdig(num)));
            sprintf(outs,"%c%0*ld",ch,numlen,ansnum);
            return outs;
        }
    }
    void dsmain() {
        char in[20]="J0921";
        puts(getNewNumber(in));
    }



    Please give credit and mark as answer :) thats all i expect in return .
    Thursday, March 22, 2007 4:17 AM
  • Yes I have the solution ..........
    Tuesday, March 27, 2007 5:55 PM
  • I couldn't ur Q....For which Q u want the Solution......my friend
    Tuesday, March 27, 2007 5:57 PM
  • Here the solution for my Q:

    #include<stdio.h>

    void sort(int *t,int n);
    int findsmall(int *t,int *reach,int n,int cond);
    int findmaxx(int x,int y);
    int findmax(int *t,int *reach,int n,int cond);

    void dsmain()
    {
    int t[5]={3,10,5,2,6};
    int n=5;
    int returns;
    returns=crossingValley(n,t);
    printf("Returns=%d",returns);
    }

    int crossingValley(int n, int* t)
    {
        int i,j,k;
        int x,y,z;
        int reach[5]={0};
        int timespent=0;
       
        sort(t,n);
       
        x=findsmall(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
       
        z=findsmall(t,reach,n,0);
        timespent+=t[Z];
       
        x=findmax(t,reach,n,1);
        y=findmax(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
       
        z=findsmall(t,reach,n,0);
        timespent+=t[Z];
       
        x=findmax(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
       
        z=findsmall(t,reach,n,0);
        timespent+=t[Z];
       
        x=findsmall(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);

        return timespent;
    }

    void sort(int *t,int n)
    {
        int i,j,temp;
        for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
        {
            if(tIdea>t[j])
            {
                temp=tIdea;
                tIdea=t[j];
                t[j]=temp;
            }
        }
    }       
           
    int findsmall(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int min;
        for(i=0;i<n && reachIdea==cond;i++);

        min=i;
       
        for(i=0;i<n;i++)
        if(tIdea<t[min] && reachIdea!=cond)
        min=i;
       
           reach[min]=cond;
           return min;  
    }

    int findmax(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int max;
        for(i=0;i<n && reachIdea==cond;i++);

        max=i;
       
        for(i=0;i<n;i++)
        if(tIdea>t[max] && reachIdea!=cond)
        max=i;
       
           reach[max]=cond;
           return max;  
    }

    int findmaxx(int x,int y)
    {
        if(x>y)
        return x;
        else
        return y;
    }   

    Tuesday, March 27, 2007 5:58 PM
  • hey this works for only less no.

    I have also worked for n people ..Let me post afterward
    Tuesday, March 27, 2007 6:01 PM
  • #include<stdio.h>
    #include<conio.h>

    int crossingValley(int n, int* t);
    void sort(int *t,int n);
    int findsmall(int *t,int *reach,int n,int cond);
    int isallreach(int *reach,int n);
    int findmaxx(int x,int y);
    int findmax(int *t,int *reach,int n,int cond);
    int nounreached(int *reach,int n);

    main()
    {
    int t[3]={10,10,11};
    int n=3;
    int returns;
    returns=crossingValley(n,t);
    printf("The time taken is %d",returns);
    getch();
    }


    int crossingValley(int n, int* t)
    {
        int i,j,k;
        int x,y,z;
        int reach[10]={0},reach2[10]={0};
        int timespent=0,timespent2=0;
        
        sort(t,n);
     
        while(!isallreach(reach,n))
        {
        x=findsmall(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
        
        if(!isallreach(reach,n))
        {
            z=findsmall(t,reach,n,0);
            timespent+=t[Z];
            
               if(nounreached(reach,n)%2==0)
               {
                   x=findmax(t,reach,n,1);
                   y=findmax(t,reach,n,1);
                   timespent+=findmaxx(t[x],tYes);
               }
               else
               {
                   x=findmax(t,reach,n,1);
                   y=findsmall(t,reach,n,1);
                   timespent+=findmaxx(t[x],tYes);
               }
               
               if(!isallreach(reach,n))
               {
                   z=findsmall(t,reach,n,0);
                   timespent+=t[Z];
               }    
        }
        }            
        

        while(!isallreach(reach2,n))
        {
        x=findsmall(t,reach2,n,1);
        y=findsmall(t,reach2,n,1);
        timespent2+=findmaxx(t[x],tYes);
        
        if(!isallreach(reach2,n))
        {
            z=findsmall(t,reach2,n,0);
            timespent2+=t[Z];
            
               if(nounreached(reach2,n)%2!=0)
               {
                   x=findmax(t,reach2,n,1);
                   y=findmax(t,reach2,n,1);
                   timespent2+=findmaxx(t[x],tYes);
               }
               else
               {
                   x=findmax(t,reach2,n,1);
                   y=findsmall(t,reach2,n,1);
                   timespent2+=findmaxx(t[x],tYes);
               }
               
               if(!isallreach(reach2,n))
               {
                   z=findsmall(t,reach2,n,0);
                   timespent2+=t[Z];
               }    
        }
        }       
            
        if(timespent<timespent2)
        return timespent;
        
        return timespent2;
    }

    void sort(int *t,int n)
    {
        int i,j,temp;
        for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
        {
            if(tIdea>t[j])
            {
                temp=tIdea;
                tIdea=t[j];
                t[j]=temp;
            }
        }
    }        
            
    int isallreach(int *reach,int n)
    {  
        int i;
        for(i=0;i<n && reachIdea==1;i++);
        if(i==n)
        return 1;
        return 0;
    }

    int findsmall(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int min;
        for(i=0;i<n && reachIdea==cond;i++);

        min=i;
        
        for(i=0;i<n;i++)
        if(tIdea<t[min] && reachIdea!=cond)
        min=i;
        
           reach[min]=cond;
           return min;   
    }
    int findmax(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int max;
        for(i=0;i<n && reachIdea==cond;i++);

        max=i;
        
        for(i=0;i<n;i++)
        if(tIdea>t[max] && reachIdea!=cond)
        max=i;
        
           reach[max]=cond;
           return max;   
    }



    int findmaxx(int x,int y)
    {
        if(x>y)
        return x;
        else
        return y;
    }   
     
    int nounreached(int *reach,int n)
    {
        int unreach=0,i;
        for(i=0;i<n;i++)
        {
            if(reachIdea==0)
            unreach++;
        }    
        return unreach;
    }
        

    Tuesday, March 27, 2007 6:02 PM
  • hope for 1000 pts
    Tuesday, March 27, 2007 6:03 PM

All replies

  • hello friend my Q is
    ---------------------

    Consider there are n number of persons who needs to cross a valley. It’s already dark out and the valley is too dark to view things out lying in the path. They need to cross the valley at the earliest time possible. They have one torch with them using that torch all the persons need to cross the valley, but the constraint is that only two persons can cross the valley at a particular time.
         Each person vary in their walking speed. You need to write a program by which all the persons cross the valley by the least time possible.

    Example 1:
    Input
        n = 3;
        t[] = {10,10,11}

    Output
        Returns 31. As the first person who can walk at a speed of 10 takes the person who walks at a speed of 11 with him leaves him at the other end returns back, joins the last person crosses the valley so the total time for taken by the three persons are 31. The calculation is done as follows, 10 + 11 as it takes 11 minutes for the third person to walk the first person leaves the third person and returns back so the total time taken for leaving the person and returning back is 11 + 10 that is 21, and joins the last person crosses the valley in 10 minutes as they both walk at the same speed. So the total time will be 21 + 10 = 31 minutes for everybody to cross the valley.

    Example 2:
    Input
        n = 5;
        t[] = {3,10,5,2,6}

    Output
        Returns 28.
    Wednesday, March 21, 2007 2:38 PM
  • NCE College of Technology is the popular college in the city. In their library department they were facing some problems in issuing and returning the book. They decided to make some changes in the books order and their unique number. So they are in need of developing new system for avoiding their problems. They will give the existing book number; you have to give the new number such a way that, a new book numbers the minimal next one with the same sum of digits and the change the alphabet according to sum and give the new book numbers.
    # Constraints: The input is a combination of one alphabet and numerical values
    # The output is INVALID if there is more than one alphabet or no alphabet, the output combinations should be greater than the input combinations and the output does not consist equal number of digits as in the input


    Example:
    Input1 = J0921
    Ouput1 = M0930.     As the sum of the digits in the input is 12 the output is the next nearest digit whose sum is 12
          The alphabet is obtained in a such a way that J(0+9+2+1)=J(12)
          J(1+2)=J(3)=J+3=M. Therefore the output is M0930.
    Input2 = 67867
    Ouput2 = INVALID
     
    Input3 = U992
    Ouput3 = INVALID     As there is no combinations greater than the input.
     
    Input4 = U0992
    Ouput4 = W1199

    For C solutions
    Header File    :    BookNumber.h
    Function Name    :    char* getNewNumber(char* number)
    Directory Name    :    booknumber
    File Name    :    booknumber.c
    For C++ solutions
    Header File    :    BookNumber.h
    Class Name    :    library
    Function Name    :    char* getNewNumber(char* number)
    Directory Name    :    booknumber
    FileName    :    booknumber.cpp

    General Instructions:
        *    

    The directory names, file / class names, functions, method signatures, header files to be used are mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods.
        *    

    First add the directory in the Main Program Directory and then add the particular file in that directory. Do not forget to mention the file extension, either .c or .cpp as the case maybe.

    Thursday, March 22, 2007 4:16 AM
  •  Harshil_Patel_03b5f2 wrote:
    NCE College of Technology is the popular college in the city. In their library department they were facing some problems in issuing and returning the book. They decided to make some changes in the books order and their unique number. So they are in need of developing new system for avoiding their problems. They will give the existing book number; you have to give the new number such a way that, a new book numbers the minimal next one with the same sum of digits and the change the alphabet according to sum and give the new book numbers.
    # Constraints: The input is a combination of one alphabet and numerical values
    # The output is INVALID if there is more than one alphabet or no alphabet, the output combinations should be greater than the input combinations and the output does not consist equal number of digits as in the input


    Example:
    Input1 = J0921
    Ouput1 = M0930. As the sum of the digits in the input is 12 the output is the next nearest digit whose sum is 12
    The alphabet is obtained in a such a way that J(0+9+2+1)=J(12)
    J(1+2)=J(3)=J+3=M. Therefore the output is M0930.
    Input2 = 67867
    Ouput2 = INVALID

    Input3 = U992
    Ouput3 = INVALID As there is no combinations greater than the input.

    Input4 = U0992
    Ouput4 = W1199

    For C solutions
    Header File : BookNumber.h
    Function Name : char* getNewNumber(char* number)
    Directory Name : booknumber
    File Name : booknumber.c
    For C++ solutions
    Header File : BookNumber.h
    Class Name : library
    Function Name : char* getNewNumber(char* number)
    Directory Name : booknumber
    FileName : booknumber.cpp

    General Instructions:
    *

    The directory names, file / class names, functions, method signatures, header files to be used are mentioned in the problem statement. Do not use your own names or change the method signatures and fields. You can add any number of additional methods.
    *

    First add the directory in the Main Program Directory and then add the particular file in that directory. Do not forget to mention the file extension, either .c or .cpp as the case maybe.





    #include"BookNumber.h"
    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
    #include<math.h>
    int cntalpha(char str[]) {
        int cnt=0,i;
        for(i=0 ; strIdea ; i++)
            if(isalpha(strIdea)) cnt++;
        return cnt;
    }
    int sumofdig(long num) {
        int sum=0;
        while(num>0)
            sum+=(num%10),num/=10;
        return sum;
    }
    char outs[80]={0};
    char* getNewNumber(char* number) {
        char ch, outch;    int numlen=0, flag, sumd=0; long i=0,num, ansnum;
        if(cntalpha(number)!=1)
            return "INVALID";
        else {
            ch=number[0];
            numlen=strlen(number)-1;
            if(!isalpha(ch)) return "INVALID";
            sscanf(number,"%c%ld",&ch,&num);
            sumd=sumofdig(num);
            for(flag=0,i=(long)num+1 ; i<(int)pow(10,numlen)-1 ; i++) {
                if(sumofdig(i)==sumd) {
                    ansnum=i;
                    flag=1;
                    break;
                }
            }
            if(flag==0) return "INVALID";
            ch+=(sumofdig(sumofdig(num)));
            sprintf(outs,"%c%0*ld",ch,numlen,ansnum);
            return outs;
        }
    }
    void dsmain() {
        char in[20]="J0921";
        puts(getNewNumber(in));
    }



    Please give credit and mark as answer :) thats all i expect in return .
    Thursday, March 22, 2007 4:17 AM
  • @Subramani,
    can you please post the solution  also ?
    Thursday, March 22, 2007 4:17 AM
  • Yes I have the solution ..........
    Tuesday, March 27, 2007 5:55 PM
  • I couldn't ur Q....For which Q u want the Solution......my friend
    Tuesday, March 27, 2007 5:57 PM
  • Here the solution for my Q:

    #include<stdio.h>

    void sort(int *t,int n);
    int findsmall(int *t,int *reach,int n,int cond);
    int findmaxx(int x,int y);
    int findmax(int *t,int *reach,int n,int cond);

    void dsmain()
    {
    int t[5]={3,10,5,2,6};
    int n=5;
    int returns;
    returns=crossingValley(n,t);
    printf("Returns=%d",returns);
    }

    int crossingValley(int n, int* t)
    {
        int i,j,k;
        int x,y,z;
        int reach[5]={0};
        int timespent=0;
       
        sort(t,n);
       
        x=findsmall(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
       
        z=findsmall(t,reach,n,0);
        timespent+=t[Z];
       
        x=findmax(t,reach,n,1);
        y=findmax(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
       
        z=findsmall(t,reach,n,0);
        timespent+=t[Z];
       
        x=findmax(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
       
        z=findsmall(t,reach,n,0);
        timespent+=t[Z];
       
        x=findsmall(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);

        return timespent;
    }

    void sort(int *t,int n)
    {
        int i,j,temp;
        for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
        {
            if(tIdea>t[j])
            {
                temp=tIdea;
                tIdea=t[j];
                t[j]=temp;
            }
        }
    }       
           
    int findsmall(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int min;
        for(i=0;i<n && reachIdea==cond;i++);

        min=i;
       
        for(i=0;i<n;i++)
        if(tIdea<t[min] && reachIdea!=cond)
        min=i;
       
           reach[min]=cond;
           return min;  
    }

    int findmax(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int max;
        for(i=0;i<n && reachIdea==cond;i++);

        max=i;
       
        for(i=0;i<n;i++)
        if(tIdea>t[max] && reachIdea!=cond)
        max=i;
       
           reach[max]=cond;
           return max;  
    }

    int findmaxx(int x,int y)
    {
        if(x>y)
        return x;
        else
        return y;
    }   

    Tuesday, March 27, 2007 5:58 PM
  • hey this works for only less no.

    I have also worked for n people ..Let me post afterward
    Tuesday, March 27, 2007 6:01 PM
  • #include<stdio.h>
    #include<conio.h>

    int crossingValley(int n, int* t);
    void sort(int *t,int n);
    int findsmall(int *t,int *reach,int n,int cond);
    int isallreach(int *reach,int n);
    int findmaxx(int x,int y);
    int findmax(int *t,int *reach,int n,int cond);
    int nounreached(int *reach,int n);

    main()
    {
    int t[3]={10,10,11};
    int n=3;
    int returns;
    returns=crossingValley(n,t);
    printf("The time taken is %d",returns);
    getch();
    }


    int crossingValley(int n, int* t)
    {
        int i,j,k;
        int x,y,z;
        int reach[10]={0},reach2[10]={0};
        int timespent=0,timespent2=0;
        
        sort(t,n);
     
        while(!isallreach(reach,n))
        {
        x=findsmall(t,reach,n,1);
        y=findsmall(t,reach,n,1);
        timespent+=findmaxx(t[x],tYes);
        
        if(!isallreach(reach,n))
        {
            z=findsmall(t,reach,n,0);
            timespent+=t[Z];
            
               if(nounreached(reach,n)%2==0)
               {
                   x=findmax(t,reach,n,1);
                   y=findmax(t,reach,n,1);
                   timespent+=findmaxx(t[x],tYes);
               }
               else
               {
                   x=findmax(t,reach,n,1);
                   y=findsmall(t,reach,n,1);
                   timespent+=findmaxx(t[x],tYes);
               }
               
               if(!isallreach(reach,n))
               {
                   z=findsmall(t,reach,n,0);
                   timespent+=t[Z];
               }    
        }
        }            
        

        while(!isallreach(reach2,n))
        {
        x=findsmall(t,reach2,n,1);
        y=findsmall(t,reach2,n,1);
        timespent2+=findmaxx(t[x],tYes);
        
        if(!isallreach(reach2,n))
        {
            z=findsmall(t,reach2,n,0);
            timespent2+=t[Z];
            
               if(nounreached(reach2,n)%2!=0)
               {
                   x=findmax(t,reach2,n,1);
                   y=findmax(t,reach2,n,1);
                   timespent2+=findmaxx(t[x],tYes);
               }
               else
               {
                   x=findmax(t,reach2,n,1);
                   y=findsmall(t,reach2,n,1);
                   timespent2+=findmaxx(t[x],tYes);
               }
               
               if(!isallreach(reach2,n))
               {
                   z=findsmall(t,reach2,n,0);
                   timespent2+=t[Z];
               }    
        }
        }       
            
        if(timespent<timespent2)
        return timespent;
        
        return timespent2;
    }

    void sort(int *t,int n)
    {
        int i,j,temp;
        for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
        {
            if(tIdea>t[j])
            {
                temp=tIdea;
                tIdea=t[j];
                t[j]=temp;
            }
        }
    }        
            
    int isallreach(int *reach,int n)
    {  
        int i;
        for(i=0;i<n && reachIdea==1;i++);
        if(i==n)
        return 1;
        return 0;
    }

    int findsmall(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int min;
        for(i=0;i<n && reachIdea==cond;i++);

        min=i;
        
        for(i=0;i<n;i++)
        if(tIdea<t[min] && reachIdea!=cond)
        min=i;
        
           reach[min]=cond;
           return min;   
    }
    int findmax(int *t,int *reach,int n,int cond)
    {
        int i=0;
        int max;
        for(i=0;i<n && reachIdea==cond;i++);

        max=i;
        
        for(i=0;i<n;i++)
        if(tIdea>t[max] && reachIdea!=cond)
        max=i;
        
           reach[max]=cond;
           return max;   
    }



    int findmaxx(int x,int y)
    {
        if(x>y)
        return x;
        else
        return y;
    }   
     
    int nounreached(int *reach,int n)
    {
        int unreach=0,i;
        for(i=0;i<n;i++)
        {
            if(reachIdea==0)
            unreach++;
        }    
        return unreach;
    }
        

    Tuesday, March 27, 2007 6:02 PM
  • hope for 1000 pts
    Tuesday, March 27, 2007 6:03 PM