毛のはえたようなもの

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

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

重複する数字を表示(Pythonの場合)

#! /user/local/bin/python // 昇順に並べる def compare_int(a,b): return b - a num=[] // ファイルからの入力 for line in open ('../data_a.txt','r'): if line == 0: break else: num.append(int(line)) // ソート num.sort(compare_int) // 同じものが…

重複する数字を表示(c++の場合)

#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(int argc,char* argv[]){ vector<int> num; int number; // ファイルからの入力 while(true){ cin >> number; if(number == 0){ break; } num.push_back(number); } // ソート sort(num.begin(), nu</int></vector></algorithm></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; char buf[1000]; int num[1000]; // ファイルからの入力 while(fgets(buf, 1000,stdin) != NULL){ if(atoi(buf) == </math.h></stdio.h>…

重複する数字を表示(Rubyの場合)

number = Array.new File.open("../data_a.txt","r"){|f| f.each{|line| (line.to_i != 0) && (number << line.to_i) } } number.sort! 1.upto(number.size-1){|i| (number[i-1] == number[i]) && (p number[i])}

C/C++/Python/Ruby比較5

読み込んだ数字のうちで重複するものを重複しただけ表示する。具体的には以下のようなデータファイルを読み込む。 35 46 62 45 2 5 35 0 // 入力の終わりは0の入力で判断する