Kamis, 07 November 2013

Life and Universe

Problem Code : TEST
Time Limit : 2 seconds
Memory Limit : 32 megabytes
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output.
Stop processing input after reading in the number 42.
All numbers at input are integers of one or two digits.

Example
Input:
1
2
88
42
99

Output:
1
2
88
 
 
Answer :
 

With c++

#include <iostream>
using namespace std;

main (){
 int in[100],a,b;
 b=0;
 for(a=0,b=0;a!=42;b++){
  cin>>a;
  in[b]=a;  
 }
 
 for(a=0;a<b-1;a++){
  cout<<in[a]<<endl;
 }
 
}
 

With java 

import java.util.Scanner;
public class Jollybee {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int in[]= new int[100],a,b;
    for(a=0,b=0;a!=42;b++){
        a = scan.nextInt();
        in[b]=a;       
    }
   
     for(a=0;a<b-1;a++){
                  System.out.println(in[a]);
    }
    }
}


 

Tidak ada komentar:

Posting Komentar