%% for SPOJ lamers use -module(tested).
-module(small_factorials).
-export([main/0]).
main() ->
{ok, [No_of_cases]} = io:fread( "", "~d" ),
loop(No_of_cases).
loop(0) ->
%%halt(1).
done;
loop(No_of_cases) ->
{ok, [Number]} = io:fread("", "~d"),
ResultFactorial = find_factorial( Number, 1 ),
io:format( "~p~n", [ResultFactorial] ),
loop( No_of_cases - 1 ).
find_factorial( 0, Product ) ->
Product;
find_factorial( Number, Product ) ->
find_factorial( Number-1, Product * Number ).
Showing posts with label Erlang. Show all posts
Showing posts with label Erlang. Show all posts
Saturday, April 28, 2012
Small factorials
( http://www.spoj.pl/problems/FCTRL2/ )
Harry and big doughnuts
( http://www.spoj.pl/problems/DOUGHNUT/ )
Erlang:
%%for SPOJ lamers use -module(tested).
-module(doughnut).
-export([main/0]).
main() ->
{ok,[Count]} = io:fread("", "~d"),
loop(Count).
loop(Count) ->
case io:fread( "", "~d ~d ~d" ) of
{ok,[C,K,W]} ->
if
C * W =< K ->
io:fwrite("~s~n", [yes]);
true ->
io:fwrite("~s~n", [no])
end,
if
Count > 1 ->
loop(Count-1);
true ->
done
end;
eof ->
done
end.
C/C++:
#include <stdio.h> // compile as C
//#include <cstdio> // decomment to compile as C++
int main() {
int t, c, k, w;
scanf("%d", &t);
while(t--) {
scanf("%d %d %d", &c, &k, &w);
if(c*w <= k) printf("yes\n");
else printf("no\n");
}
return 0;
}
Subscribe to:
Posts (Atom)