Thursday, September 13, 2018

AMELIA DICE


  • Problem Description

    Amelia designed a game of triangle with 2 players. She names the points of her triangle as p1,p2 and p3. She moved over her coin in these points. She used a special dice which could bring out numbers from 1 to 100. In every move if the number of the dice takes moves in multiple of 3, the player scores additional 10 points. Amelia wants to write a C program to pick out numbers that are multiple of 3 using the concept of arrays and pointers. Your task is to help her write the code using pointers and arrays and print the numbers divisible by 3. The array contains the sequence of numbers occuring in the dice. 
    Input : 
    The first line contains the no of test cases, 0<T<=10000, 
    The Second line contains the no of array elements n of test case 1, 0<n<=100, 
    The third line contains the n integers separated by a space. 
    For T test cases the second and third lines are successively entered. 

    Output: 
    The number that is divisible by 3, 
    If T <0 or T>10000 
    print " Invalid Input" . 
    If n<0 or n>100 print "Invalid Input"
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int i,t,n,a[n];
      scanf("%d%d",&t,&n);
      for(i=0;i<n;i++)
        scanf("%d",&a[i]);
      if(t<=10000)
      {
        for(i=0;i<n;i++)
        {
          if(a[i]%3==0)
            printf("%d\n",a[i]);
        }
      }
      else
        printf("Invalid Input");
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    1
    
    5
    
    1 12 3 4 15
    
    
    Expected Output
    12
    
    3
    
    15
  • Test Case 2

    Input (stdin)
    10001
    
    5
    
    1 2 3 4 5
    
    
    Expected Output
    Invalid Input

No comments:

Post a Comment