User Tools

Site Tools


pl_2f_bf_ac_bd_c0_b9_ae_c1_a63

'전자정보공학부 200012911 박동희 '

open TextIO;

fun digit(c) =
    ord(c) - ord(#"0");

fun str2chrList(string) =
    explode(string)

fun skipEOL(L) =
    if L = nil
       then []
    else if hd(L) = #"\n"
	    then skipEOL(tl(L))
    else
	[hd(L)]@skipEOL(tl(L))

fun exlistinlist ([h]::hs) =
    if hs = []
       then [h*h]
    else h*h::exlist2(hs);	    

fun exlist (h::hs) =
    if hs = nil
       then [h*h]
    else h*h::exlist(hs);	    

fun charL2intL(L) =
    if L = nil
       then 0::[]
    else if hd(L) = #" "
       then 0::charL2intL(tl(L))
    else digit(hd(L))::charL2intL(tl(L));

fun tokeningIntList(L, intsofar) =
    if L = nil
       then []
    else if hd(L) = 0
       then intsofar::tokeningIntList(tl(L), 0)
    else tokeningIntList(tl(L), 10*intsofar+hd(L));

fun listfileOut(infile,outfile) = 
    let
	val ins = TextIO.openIn infile
	val outs = TextIO.openOut outfile
    in		   
	(TextIO.output(outs, "[");
	sk(outs, intTostrl(exlist(tokeningIntList(charL2intL(skipEOL(str2chrList(TextIO.inputLine(ins)))),0))));
	TextIO.output(outs, "[");
	sk(outs, intTostrl(exlist(tokeningIntList(charL2intL(skipEOL(str2chrList(TextIO.inputLine(ins)))),0))));
	TextIO.output(outs, "[");
	sk(outs, intTostrl(exlist(tokeningIntList(charL2intL(skipEOL(str2chrList(TextIO.inputLine(ins)))),0))));
	TextIO.output(outs, "[");
	sk(outs, intTostrl(exlist(tokeningIntList(charL2intL(skipEOL(str2chrList(TextIO.inputLine(ins)))),0))));
	TextIO.closeOut outs)
    end;listfileOut("tt1","out");

fun sk(stroem, (x::nil)) = TextIO.output(stroem,x^"]\n")
  | sk (stroem,(x::s)) =  (TextIO.output(stroem,x^","); sk(stroem,s));

fun listfileOut(infile,outfile) = 
    let
	val ins = TextIO.openIn infile
	val outs = TextIO.openOut outfile
    in		   
	(sk(outs, readlist(ins));
	TextIO.closeOut outs)
    end;

listfileOut("ttt","out");

fun readlist(ins) =
    if endOfStream(ins) then nil
    else TextIO.inputLine(ins)::readlist(ins)

fun sk(stroem, (x::nil)) = TextIO.output(stroem,x)
  | sk (stroem, (x::s)) = (TextIO.output(stroem,x);sk(stroem,s));

fun intTostrl(h::nil) = [Int.toString(h)]
  | intTostrl(h::t) = 
    [Int.toString(h)]@intTostrl(t);
pl_2f_bf_ac_bd_c0_b9_ae_c1_a63.txt · Last modified: 2018/07/18 14:10 by 127.0.0.1