Thursday, January 21, 2010

My submissions to SPOJ problem- TEST

My interest lies in programming languages. Actually, I have a bad habit of trying every type of weird thing and this time I came up with the idea of trying a simple problem in every possible programming language I know. I tried to solve the first problem of SPOJ named Test. Here are my codes:

C:

#include < stdio.h >

int main()
{
int n;
scanf("%d",&n);
while (n!= 42) {
printf(""%d", n);
scanf("%d",&n);
}
return 0;
}

C++:

#include < iostream >
using namespace std;

int main()
{
int n;
cin>>n;
while (n!= 42) {
cout<>n;
}
return 0;
}

C#:

using System;
public class Test
{
public static void Main()
{
int n;
while ((n = int.Parse(Console.ReadLine()))!=42)
Console.WriteLine(n);
}
}

Java:

public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42"))
System.out.println(s);
}
}

Python:

n = input()
  while n != 42:
  print n
  n = input()

PHP:

< ? php while(1) { fscanf(STDIN,"%d",$n); if ($n == 42) break; print "$n\n"; } ? >


BrainF*ck:

>+[>>,----------[>,----------]+++++[<-------->-]<[>>-<]>+[
-<+++++++[<------>-]<[>>-<]>+[
-<<[>>-<]>+[<<->>->]>
]<+++++++[<++++++>-]>>
]<++++++++[<+++++>-]< [<]<[>>[++++++++++.>]++++++++++.[[-]<]]<]
* * * * *

2 comments: