毛のはえたようなもの

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

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

範囲に収まる数字の数(Pythonの場合)

#! /user/local/bin/python num = [] chohuku =0 for line in open ('../data_d.txt','r'): if line == 0: break else: num.append(int(line)) width = num.pop(0); num.sort(lambda x, y: y-x) maxTimes =0 for i in range(len(num)-1): target = 0 for j i…

範囲に収まる数字の数(c++の場合)

#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void){ int width; cin >> width; vector<int> num; int number; while(true){ cin >> number; if(number == 0) break; num.push_back(number); } sort(num.begin(), num.end(),greater<int>()); int i=0</int></int></algorithm></vector></iostream>…

範囲に収まる数字の数(c言語の場合)

#include <stdio.h> #include <math.h> int compare_int(const int *a,const int *b){ return *b- *a; } int main(){ int i = 0; int j = 0; int k = 0; char buf[1000]; int num[1000]; int flag=0; int w; int max=0; int target=0; while(fgets(buf, 1000,stdin) != NULL){</math.h></stdio.h>…

範囲に収まる数字の数(Rubyの場合)

number = Array.new File.open("../data_d.txt","r"){|f| f.each{|line| (line.to_i != 0) && (number << line.to_i) } } width = number.shift number.sort! maxTimes =0 number.size.times{|i| tmpTimes = 0 i.upto(number.size){|j| if (number[j].to_i -…

C/C++/Python/Ruby比較7

ある数字列が与えられたとき、指定された範囲に収まる数字の数を表示。 例えば以下のようなデータが与えられる。 6 //初めの行は幅 3 //データ始まり 56 6 43 39 27 13 62 0 //データの終わりは0で示される