100 likes | 213 Views
湘南工科大学. 2014 年 1 月 14 日. 情報 理論2. 湘南工科大学情報工学科 准教授 小林 学. [ 前回の課題1解答 ] 連続 一致文字数の最大値と,最大値の位置( i )を出力 しなさい. Page 2. #include< stdio.h > int Dat [16]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; int Icchicho ( int n ){ // n 番目と 8 番目から連続一致する長さを返す int i , count=0; for( i =0 ; i <8; i ++){
E N D
湘南工科大学 2014年1月14日 情報理論2 湘南工科大学情報工学科 准教授 小林 学
[前回の課題1解答] 連続一致文字数の最大値と,最大値の位置(i)を出力しなさい Page 2 #include<stdio.h> intDat[16]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; intIcchicho(int n){ // n 番目と8番目から連続一致する長さを返す inti, count=0; for(i=0; i<8; i++){ if(Dat[i+n] == Dat[i+8]) count++; else break; } return(count); } void main(void){ int ans, i, max, pos; max=0; pos=0; for(i=0; i<8; i++){ ans= Icchicho(i); if(ans> max){ max = ans; pos= i; } } printf("pos:%d, max:%d\n",pos,max); }
[用紙の課題1] 以下のプログラムの出力を書きなさい. Page 3 #include<stdio.h> intDat[16]={0,1,2,0,2,0,0,1,2,0,0,2,1,-1}; intIcchicho(int n){ // n 番目と8番目から連続一致する長さを返す inti, count=0; for(i=0; i<8; i++){ if(Dat[i+n] == Dat[i+8]) count++; else break; } return(count); } void main(void){ int ans, i, max, pos; max=0; pos=0; for(i=0; i<8; i++){ ans= Icchicho(i); if(ans> max){ max = ans; pos= i; } printf(“i:%d, pos:%d, max:%d\n",i, pos,max); } }
[前回の課題2解答] Shift関数を用いて「最大連続一致文字数+1」だけ配列Datを Shift させなさい. Page 4 #include<stdio.h> intDat[16]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; intIcchicho(int n){・・同じ・・ } void Shift(int n){ int i; for(i=0; i<16-n; i++) Dat[i] = Dat[i+n]; } void main(void){ int ans, i, max, pos; max=0; pos=0; for(i=0; i<8; i++){ ・・同じ・・ } printf("pos:%d, max:%d\n",pos,max); Shift(max+1); }
[用紙の課題2]以下のプログラムの出力を書きなさい.[用紙の課題2]以下のプログラムの出力を書きなさい. Page 5 #include<stdio.h> intDat[16]={0,1,2,0,2,0,0,1,2,0,0,2,1,-1}; intIcchicho(int n){・・同じ・・ } void Shift(int n){ int i; for(i=0; i<16-n; i++) Dat[i] = Dat[i+n]; } void main(void){ int ans, i, max, pos; max=0; pos=0; for(i=0; i<8; i++){ ・・同じ・・ } Shift(max+1); for(i=0;i<16;i++) printf("%d ",Dat[i]); }
[前回の課題3解答] (最大連続一致位置,最大連続一致数,一致しなかった数値)」を画面に出力すること.一致しなかった数値が「-1」の場合,出力して終了とすること. #include<stdio.h> intDat[16]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; intIcchicho(int n){・・同じ・・ } void Shift(int n){・・同じ・・} void main(void){ intans, i, max, pos; while(1){ max=0; pos=0; for(i=0; i<8; i++){・・同じ・・} printf("(%d,%d,%d)\n",pos,max,Dat[8+max]); if(Dat[8+max]==-1) break; Shift(max+1); } }
[用紙の課題3]以下のプログラムの出力を書きなさい.[用紙の課題3]以下のプログラムの出力を書きなさい. #include<stdio.h> intDat[16]={0,1,2,0,2,0,0,1,2,0,0,2,1,-1}; intIcchicho(int n){・・同じ・・ } void Shift(int n){・・同じ・・} void main(void){ intans, i, max, pos; while(1){ max=0; pos=0; for(i=0; i<8; i++){・・同じ・・} printf("(%d,%d,%d)\n",pos,max,Dat[8+max]); if(Dat[8+max]==-1) break; Shift(max+1); } }
[プログラミング課題1]以下のプログラムを作成しなさい[プログラミング課題1]以下のプログラムを作成しなさい Page 8 #include<stdio.h> #define MADO 8 intDat[2*MADO]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; intIcchicho(int n){ // n 番目と8番目から連続一致する長さを返す inti, count=0; for(i=0; i<MADO; i++){ if(Dat[i+n] == Dat[i+MADO]) count++; else break; } return(count); } void main(void){ int ans, i, max, pos; max=0; pos=0; for(i=0; i<MADO; i++){ ans= Icchicho(i); if(ans> max){ max = ans; pos= i; } printf("i:%d, pos:%d, max:%d\n",i, pos,max); } }
[プログラミング課題2]以下のプログラムを作成しなさい[プログラミング課題2]以下のプログラムを作成しなさい Page 9 #include<stdio.h> #define MADO 8 intDat[2*MADO]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; intIcchicho(int n){・・同じ・・ } void Shift(int n){ int i; for(i=0; i<2*MADO-n; i++) Dat[i] = Dat[i+n]; } void main(void){ int ans, i, max, pos; max=0; pos=0; for(i=0; i<MADO; i++){・・同じ・・ } printf("pos:%d, max:%d\n",pos,max); Shift(max+1); }
[プログラミング課題3]以下のプログラムを作成しなさい[プログラミング課題3]以下のプログラムを作成しなさい #include<stdio.h> #define MADO 8 intDat[2*MADO]={0,1,0,1,2,0,2,0,0,1,2,0,1,2,1,-1}; intIcchicho(int n){・・同じ・・ } void Shift(int n){・・同じ・・} void main(void){ intans, i, max, pos; while(1){ max=0; pos=0; for(i=0; i<MADO; i++){・・同じ・・} printf("(%d,%d,%d)\n",pos,max,Dat[MADO+max]); if(Dat[MADO+max]==-1) break; Shift(max+1); } }