• 検索結果がありません。

if( yonketa(j,u,d,o)+yonketa(w,a,z,a) == goketa(i,p,p,o,n) ) word[0]=a; word[1]=d; word[2]=i; word[3]=j; word[4]=n; word[5]=o; word[6]=p; word[7]=u; w

N/A
N/A
Protected

Academic year: 2021

シェア "if( yonketa(j,u,d,o)+yonketa(w,a,z,a) == goketa(i,p,p,o,n) ) word[0]=a; word[1]=d; word[2]=i; word[3]=j; word[4]=n; word[5]=o; word[6]=p; word[7]=u; w"

Copied!
18
0
0

読み込み中.... (全文を見る)

全文

(1)

学籍番号1110064 氏名 菅原 誠大 【問題1】覆面算の答えを求めるプログラム (1) 複数個(10 個未満)の答えが出るもの 完成したプログラム(プログラムの説明を含む) /* hukumenzan

judo + waza = ippon */

#include <stdio.h>

int yonketa(int n1,int n2,int n3,int n4); int goketa(int n1,int n2,int n3,int n4,int n5); int tigau(int *p);

int k,l;

void hyouji(int *word); int main(void) { int a,d,i,j,n,o,p,u,w,z; int word[10],kazu=1; printf("judo+waza=ippon¥n"); for(a=0;a<10;a++){ for(n=0;n<10;n++){ for(o=0;o<10;o++){ for(d=0;d<10;d++){ for(z=0;z<10;z++){ for(u=0;u<10;u++){ for(p=0;p<10;p++){ for(j=1;j<10;j++){ /*最高位の文字には0を当てない*/ for(w=1;w<10;w++){ /*最高位の文字には0を当てない*/ for(i=1;i<10;i++){ /*最高位の文字には0を当てない*/

(2)

if( yonketa(j,u,d,o)+yonketa(w,a,z,a) == goketa(i,p,p,o,n) ) { word[0]=a; word[1]=d; word[2]=i; word[3]=j; word[4]=n; word[5]=o; word[6]=p; word[7]=u; word[8]=w; word[9]=z; if( tigau(word) ) { printf("%d ---> ",kazu++); hyouji(word); } } } } } } } } } } } } printf("--- Owari ---¥n"); return 0; } /* 結果を表示する関数 */

(3)

void hyouji(int *word) { printf(" %d%d%d%d ¥n",word[3],word[7],word[1],word[5]); printf(" +%d%d%d%d ¥n",word[8],word[0],word[9],word[0]); printf(" ---¥n"); printf(" %d%d%d%d%d¥n",word[2],word[6],word[6],word[5],word[4]); printf(" ¥n");} /* 4 つの数を 4 桁の整数にする関数 */ int yonketa(int n1,int n2,int n3,int n4) { return n1*1000+n2*100+n3*10+n4; } /* 5 つの数を 5 桁の整数にする関数 */ int goketa(int n1,int n2,int n3,int n4,int n5) { return n1*10000+n2*1000+n3*100+n4*10+n5; } /* 配列の要素の中に同じものがあるとき kekka=0 を返す関数 */ int tigau(int *p) {int kekka=1; for(l=1;l<=9;l++){ for(k=1;k<=l;k++){ if( *(p+9-l) == *(p+9-l+k)) kekka=0; } } return kekka; }

(4)
(5)

(2) 答えが一個しかないもの

完成したプログラム(プログラムの説明を含む) /* hukumenzan

tokyo + kyoto = akarui */

#include <stdio.h>

int goketa(int n1,int n2,int n3,int n4,int n5);

int rokuketa(int n1,int n2,int n3,int n4,int n5,int n6); int tigau(int *p);

int s,t;

void hyouji(int *word);

int main(void) { int a,i,k,o,r,t,u,y; int word[8],kazu=1; printf("tokyo+kyoto=akarui\n"); for(a=1;a<10;a++){ /*最高位の文字には0を当てない*/ for(i=0;i<10;i++){ for(k=1;k<10;k++){ /*最高位の文字には0を当てない*/ for(o=0;o<10;o++){ for(r=0;r<10;r++){ for(t=1;t<10;t++){ /*最高位の文字には0を当てない*/ for(u=0;u<10;u++){ for(y=0;y<10;y++){ if(goketa(t,o,k,y,o)+goketa(k,y,o,t,o) == rokuketa(a,k,a,r,u,i)) { word[0]=a; word[1]=i; word[2]=k;

(6)

word[3]=o; word[4]=r; word[5]=t; word[6]=u; word[7]=y; if( tigau(word) ) { printf("%d ---> ",kazu++); hyouji(word); } } } } } } } } } } printf("--- Owari ---\n"); return 0; } /* 結果を表示する関数 */ void hyouji(int *word)

{ printf(" %d%d%d%d%d \n",word[5],word[3],word[2],word[7],word[3]); printf(" +%d%d%d%d%d \n",word[2],word[7],word[3],word[5],word[3]); printf(" ---\n"); printf(" %d%d%d%d%d%d\n",word[0],word[2],word[0],word[4],word[6],word[1]) ; printf(" \n");}

(7)

/* 5 つの数を 5 桁の整数にする関数 */

int goketa(int n1,int n2,int n3,int n4,int n5) { return n1*10000+n2*1000+n3*100+n4*10+n5; }

/* 6 つの数を 6 桁の整数にする関数 */

int rokuketa(int n1,int n2,int n3,int n4,int n5,int n6) { return n1*100000+n2*10000+n3*1000+n4*100+n5*10+n6; } /* 配列の要素の中に同じものがあるとき kekka=0 を返す関数 */ int tigau(int *p) {int kekka=1; for(s=1;s<=7;s++){ for(t=1;t<=s;t++){ if( *(p+7-s) == *(p+7-s+t)) kekka=0; } } return kekka; }

(8)

実行結果 (3) 工夫したところ、苦労したところ ・覆面算の解は覆面算ソルバー(http://bach.istc.kobe-u.ac.jp/llp/crypt-jp.html) を用いて求めた。特に、解が一個しかない場合を発見するのに約一週間掛かった。 ・最高位の文字には0を当てないようにした。また、0を当てないことで、無駄な計 算を省き、計算時間を短縮させた。 ・「配列の要素の中に同じものがあるとき kekka=0 を返す関数」の作成では、for 文 を用いて、当初の先生のプログラムより簡略化した。

(9)

【問題2】(1)これから処理する英語の文書 出所(出典)

(http://www.nier.go.jp/saka/rika/eigo2.txt)

In the advancement of Japanese science and technology, it is particularly important to increase public motivation in and awareness of science and technology which constitutes an important part of our society, by taking advantage of various opportunities.

Public understanding of science and technology is an indispensable social foundation for a nation based on creativity of science and technology.

For this purpose, the function of scientific museums, which are important learning places concerning science, has been enhanced and effectively used.

More specifically, model museums as the center of communities, in coordination with other museums, schools and related organizations in the community, have developed educational materials for experiments by exploiting the expertise and characteristic of each museum.

It has also introduced interactive exhibits and experiential activities, where children can enjoyably learn nature, technology, history and traditional culture on holiday Saturdays and other available days.

(10)

(2)アルファベットの大文字の数、小文字の数、記号等の数、アルファベットの総数(記 号等を含む) 完成したプログラム(プログラムの説明を含む) #include <stdio.h> int main(void) { int i=0,j=0,h=0,c; FILE *fp; fp=fopen("z:\\test001.txt","r"); if (fp==NULL) { printf("ファイルが見つかりません。\n"); return 0; } while ((c=fgetc(fp))!=EOF){ printf("%c",c); /*ASCII コード(アスキーコード)を用いて文字を場合分けする*/ if(65<=c && c<=90) i++;

if((33<=c && c<=64) || (91<=c && c<=96) || (123<=c && c<=126) ) h++; if(97<=c && c<=122) j++; } printf("アルファベットの大文字の数は%d\n",i); printf("アルファベットの子文字の数は%d\n",j); printf("記号等の数は%d\n",h); printf("アルファベットの総数(記号等を含む)は%d\n",i+j+h); fclose(fp); return 0; }

(11)
(12)

(3) 小文字を大文字に変換して表示 完成したプログラム(プログラムの説明を含む) #include <stdio.h> int main(void) { int c; FILE *fp; fp=fopen("z:\\test001.txt","r"); if (fp==NULL) { printf("ファイルが見つかりません。\n"); return 0; } while ((c=fgetc(fp))!=EOF){ /*ASCII コード(アスキーコード)を用いて小文字の場合のとき*/ if(97<=c && c<=122){ /*小文字を大文字に変換*/ c-=32; } printf("%c",c); } fclose(fp); return 0; }

(13)
(14)

(4) 長さが1番長い単語を表示 完成したプログラム(プログラムの説明を含む) #include <stdio.h> /*文字列操作数関数【string.h】を使い strlen、strtok を用いる*/ #include <string.h> int main(void) { char s[256],*p,word[256]; int max=0,len; FILE *fp; fp=fopen("z:\\test001.txt","r"); if (fp==NULL){ printf("ファイルが見つかりません。\n"); return 0; } while(fgets(s, 256, fp)!=NULL) { printf("%s",s); /*空白または,または.改行ごとに単語に分割*/ p=strtok(s, " ,.\"\n"); while(p!=NULL){ /*空白または,または.改行ごとに単語に分割*/ p=strtok(NULL," ,.\"\n"); if(p!=NULL){ /*文字の長さを測る*/ len=strlen(p); /*長さが一番長いものを選ぶ*/ if(max<len){ max=strlen(p); strcpy(word,p); } } } } printf("長さが1番長い単語 %s\n",word); fclose(fp);

(15)

return 0; }

(16)

(5) 上記以外で、自分で何か調べてみたいこと 英文から masahiro はいくつ作れるかを調べた。 完成したプログラム(プログラムの説明を含む) #include <stdio.h> int main(void) { int a=0,h=0,i=0,m=0,o=0,r=0,s=0,a1,z,min=0,namae,c; FILE *fp; fp=fopen("z:\\test001.txt","r"); if (fp==NULL) { printf("ファイルが見つかりません。\n"); return 0; } while ((c=fgetc(fp))!=EOF){ printf("%c",c); /*a の数を求める*/ if(c==97) a++; /*h の数を求める*/ else if(c==104) h++; /*i の数を求める*/ else if(c==105) i++; /*m の数を求める*/ else if(c==109) m++; /*o の数を求める*/ else if(c==111) o++; /*r の数を求める*/ else if(c==114) r++;

(17)

/*s の数を求める*/ else if(c==115) s++; } /*a の個数で場合分けする*/ if(a%2==0) a1=a/2; else a1=(a-1)/2; /*masahiro を作るための a,h,i,m,o,r,s の個数で最小のものを求める*/ char t[7]={a1,h,i,m,o,r,s}; for(z=0;z<7;z++){ if(t[min]>t[z]) namae=t[z]; } printf("a の数は%d\n",a); printf("h の数は%d\n",h); printf("i の数は%d\n",i); printf("m の数は%d\n",m); printf("o の数は%d\n",o); printf("r の数は%d\n",r); printf("s の数は%d\n",s);

printf("よって英文から masahiro は%d 作れる\n",namae); fclose(fp);

return 0; }

(18)

実行結果 (6)工夫したところ、苦労したところ ・(4)では文字列操作数関数【string.h】を使い、文字数を調べるために strlen、空白 または,または.改行ごとに単語に分割を strtok を用いた。 ・(2)では実行結果のアルファベットの大文字の数、小文字の数、記号等の数、アルフ ァベットの総数(記号等を含む)が正しいか word を用いて検証した。

参照

関連したドキュメント

2022 年9月 30 日(金)~10 月 31 日(月)の期間で東京・下北沢で開催される「下北沢カレーフェステ ィバル 2022」とのコラボ企画「MANKAI

日臨技認定センターの認定は 5 年毎に登録更新が必要で、更新手続きは有効期間の最終

Tatanmame, … Si Yu’us unginegue Maria, … Umatuna i Tata … III (MINA TRES) NA ESTASION.. ANAE BASNAG SI JESUS FINENANA NA BIAHE Inadora hao Jesukristo ya

大六先生に直接質問をしたい方(ご希望は事務局で最終的に選ばせていただきます) あり なし

のようにすべきだと考えていますか。 やっと開通します。長野、太田地区方面  

○社会福祉事業の経営者による福祉サービスに関する 苦情解決の仕組みの指針について(平成 12 年6月7 日付障第 452 号・社援第 1352 号・老発第

The procedure given in Section 4 detects representa- tions which are discrete and faithful with torsion–free image, by constructing a fundamental domain for the induced action

○ 4番 垰田英伸議員 分かりました。.