毛のはえたようなもの

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

2007-10-01から1ヶ月間の記事一覧

Ubuntu7.10インストールログ

7.06からアップデートしようとしたのですが、どこかでカーネルを壊したらしい私。リカバリーモードでは立ち上がるのにGUIはだめ。うーん。Xとか壊したかしらん。 いずれにせよヾ(・∀・)ノシ オワタと言うわけで7.10クリーンインストールです。前回のインストール…

ネットワークプログラミング1

socketを使おう!の巻。説明は面倒くさいのでしないというか、私もよくわかってない(o^▽^o) #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define PORT 5555 void err_check(int res, char function_name[]); int main(int argc , char* argv[]){ int new_socke</netdb.h></netinet/in.h></sys/socket.h></stdio.h>…

範囲に収まる数字の数(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で示される

相異なる文の種類の数(Pythonの場合)

#! /user/local/bin/python import string num = [] chohuku =0 for line in open ('../data_c.txt','r'): if line == 0: break else: num.append(line) num.sort(lambda x, y: cmp(string.lower(x), string.lower(y))) for i in range(len(num)-1): if num[…

相異なる文の種類の数(c++の場合)

#include <string> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(void){ vector<string> line; string oneString; while(getline(cin,oneString) ){ if(oneString == "") break; line.push_back(oneString); } sort(line.begin(), line.end(),greater<string>()); i</string></string></algorithm></vector></iostream></string>…

相異なる文の種類の数(c言語の場合)

#include <stdio.h> #include <math.h> #include <string.h> int cmp(const char *a,const char *b){ return strcmp(b,a); } int main(void){ char buf[1000]; FILE *stream; char string[10001][70]; int i = 0; int j = 0; int chohuku =0; while(fgets(buf, 1000,stdin) != NULL){ st</string.h></math.h></stdio.h>…

相異なる文の種類の数(Rubyの場合)

ary = Array.new File.open("../data_c.txt","r"){|f| f.each{|line| line.chomp! !="" && ary << line } } p (ary|ary).size Rubyみじかっ

C/C++/Python/Ruby比較6

文字列を読み込み、相異なる文の種類の数を表示する。具体的には以下のデータで7と表示されればよい。 Is this the first line? Yes, it is. This is the second. I think that was the third. Is this the first line? No, it is not. But this is not the…

重複する数字を表示(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の入力で判断する

k番目に大きい数(Rubyの場合)

flag = 0 k,n = 0, 0 number = Array.new File.open("../data_d.txt","r"){|f| f.each{|line| if flag == 0 n,k = line.split.collect{|i| i.to_i} flag = 1 elsif flag && number.size < n number << line.to_i end } } p number.sort_by{|i| -i}[k-1]

k番目に大きい数(Pythonの場合)

#! /user/local/bin/python def compare_int(a,b): return b - a flag=0 number=[0] for line in open ('../data_d.txt','r'): if flag==0: line.split(" ") n = int(line[0]) k= int(line[2]) flag = 1 else: if int(line)!=0: number.append(int(line)) nu…

k番目に大きい数(c++の場合)

#include <iostream> using namespace std; int compare_int(const int *a,const int *b){ return *b - *a; } int main(int argc,char* argv[]){ int num[1000]; int n, k, x; int i=0; cin >> n; cin >> k; while(cin >> num[i]){ i++; } qsort(num,n,sizeof(int),(in</iostream>…

k番目に大きい数(cの場合)

#include <stdio.h> #include <string.h> int compare_int(const int *a,const int *b){ return *b- *a; } int main(){ int num[1000]; char string[1000]; int n ,k ,x; int i=0; fgets(string, 1000,stdin); sscanf(string,"%d %d",&n,&k); while(fgets(string, 1000,stdin) !</string.h></stdio.h>…

C/C++/Python/Ruby比較4

ファイルから読み取ったn個の数のうち、k番目に大きい数を表示せよ。ただし、ファイルの内容は以下のようなものとする。 5 3 // 「n k」ということ 1 300 200 4 55 0 //最後は0

右側折り返し(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文字の場合)

精度を要する割り算(Pythonの場合)

#!/usr/bin/env python import sys for line in open ('../data_b.txt','r'): item = line.split(' ') if float(item[0])!=0 and float(item[1])!=0: print float(item[0])/float(item[1])

精度を要する割り算(c++の場合)

#include <iostream> #include <iomanip> using namespace std; int main(int argc,char* agrc[]){ double a; double b; while(true){ cin >> a; cin >> b; if(a==0 && b==0){ break; }else{ cout << setprecision(10) << a/b << endl; } } return 0; }</iomanip></iostream>

精度を要する割り算(cの場合)

#include <stdio.h> int main(){ char string[10000]; double a, b; while(fgets(string, 10000,stdin) != NULL){ sscanf(string,"%d %d",&a,&b); if(a==0 && b==0){ break; }else{ printf("%0.10f\n",a/b); } } return 0; }</stdio.h>