Saturday, April 28, 2012

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;
}

No comments:

Post a Comment