毛のはえたようなもの

インターネット的なものをつらつらとかきつらねる。

2007-10-04から1日間の記事一覧

右側折り返し(Rubyの場合)

maxlength = 72 File.open("../data_c.txt","r"){|f| f.each{|line| line.chomp! (line.size/maxlength).times{|i| line[maxlength*(i+1)+i,0] = "\n" } print line+"\n" } }

右側折り返し(Pythonの場合)

#! /user/local/bin/python maxlength = 72 text="" def insert_sp(i,text,line): if i!=0 and (i)%maxlength ==0: text = text + "\n" if line[i] == "\n": print text else: text = text + line[i] insert_sp(i+1,text,line) for line in open('../data_c.…

右側折り返し(c++の場合)

#include <iostream> using namespace std; int main(void){ int num=0; char word; int maxlength=71; while(cin.get(word)){ if(word == '\n'){ num=0; }else if(num > maxlength){ cout << endl; num=0; }else{ num++; } cout << word; } return 0; }</iostream>

右側折り返し(cの場合)

#include <stdio.h> int main(void){ int num=0; char word; FILE *stream; int maxlength=71; stream = fopen("../data_c.txt","r"); while((word = getc(stream)) != EOF){ if(word == '\n'){ num=0; }else if(num > maxlength){ printf("\n"); num=0; }else{ num++</stdio.h>…

C/C++/Python/Ruby比較3

読み込んだファイルの内容を表示する。ただし、指定した文字数で改行すること。(以下は一行72文字の場合)