毛のはえたようなもの

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

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

標準入力から一行づつ読み込み最大値を表示(Pythonの場合)

#! /user/local/bin/python first=0 for line in open('../data_a.txt','r'): num = int(line) if first !=1 or max < num: max = num first =1 print max

標準入力から一行づつ読み込み最大値を表示(C++の場合)

#include <iostream> using namespace std; int main(int argc,char* agrc[]){ int max, num; bool flag = false; while(cin){ cin >> num; if(flag ==false || max < num){ flag =true; max = num; } } cout << max << endl; return 0; }</iostream>

標準入力から一行づつ読み込み最大値を表示(Cの場合)

#include <stdio.h> #include <string.h> int main(){ int max; char buf[1000]; char* num; int flag = 0; while(fgets(buf, 1000,stdin) != NULL){ num = strtok(buf," \n"); while(num != NULL){ if(flag == 0 || max < atoi(num)){ flag = 1; max = atoi(num); } num =strto</string.h></stdio.h>…

標準入力から一行づつ読み込み最大値を表示(Rubyの場合)

ar = Array.new File.open("../data_a.txt","r"){|f| f.each{|num| ar << num.chomp!.to_i } } p ar.max

C/C++/Python/Ruby比較1

「標準入力から一行づつ読み込み最大値を表示」の言語による比較。読み込むファイルは改行区切りの数が保存されているものとする。