Paste: spoj's ADDREV

Author: piranha
Mode: factor
Date: Fri, 16 Jan 2009 14:55:11
Plain Text |
#! /home/piranha/bin/factor -script

USING: io kernel math math.parser sequences splitting ;
IN: rev

: strip0 ( num -- num ) [ dup 10 mod 0 = ] [ 10 / ] [ ] while ;

: getnums ( s -- n1 n2 ) " " split1 [ <reversed> string>number ] bi@ ;
: revnum ( n1 n2 -- s ) + strip0 number>string reverse ;

: perform ( input -- output ) getnums revnum ;

: go ( -- ) readln drop
    [ readln dup ]
    [ perform print ]
    [ drop ] while ;

go

Annotation: input

Author: piranha
Mode: factor
Date: Fri, 16 Jan 2009 15:46:04
Plain Text |
piranha@gtv ~/dev/_exp/spoj>head rev.inp
140400
24 1
4358 754
305 794
24 1
4358 754
305 794
24 1
4358 754
305 794
piranha@gtv ~/dev/_exp/spoj>cat rev.inp|wc -l    
140401

Annotation: python version

Author: piranha
Mode: factor
Date: Fri, 16 Jan 2009 19:23:21
Plain Text |
#!/usr/bin/env python

import sys

xr = sys.stdin.xreadlines()
xr.next()
for l in xr:
    one, two = l.split()
    print str(int(one[::-1]) + int(two[::-1]))[::-1].lstrip('0')

New Annotation

Summary:
Author:
Mode:
Body: