演習問題 9

1) デ−タファイル(ファイル名sumo.d)がある。このファイルの内容を次に示す。

----+----1----+----2----+----3----+----4----+----5----+----6----+----7
   Yesterday when I got on the train in Shibuya, I had a big          
 surprise, and I mean big! There were three sumo wrestlers on the     
 train. I was standing by the door right next to one of them, but I   
didn't recognize him. The other two were sitting behind me. I really  
    :
    :
aprons, I think, "Wow! I'm really in Japan," and I feel happy to      
be here. And that was just how I felt on the train yesterday too.     
                                                                      
File end            NHK ラジオ英会話テキストより                      
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
前後の目盛りの行は除く。

このファイルを読んで、文字 A または a 、文字列 The または the がファイル中に何個含まれているか数えよ。ファイルの終わりは行の先頭の文字列'File end'で判断し、その行は対象としない。

ヒント
文字変数 m ( character m*70 )に一行分のデータを読み込む。
m(1:1),m(2:2), ... ,m(70:70) について、A または a に等しいか調べて数える。
また、m(1:3),m(2:4), ... ,m(68:70) について、The または the に等しいか調べて数える。
これをデータの終わりまで繰り返す。
Fortranの文法文字処理を参照。

2) 1)のデータファイルを読んで、使用されている単語と単語の使用度数を調べ、使用度数の高いものから順に単語とその使用度数を10個まで出力せよ。The と the のような大文字と小文字の違いは別の単語として数えてよい。

ヒント
単語を区切っている文字は、空白 , . " ! である。
文字変数 m ( character m*70 )に一行分のデータを読み込む。
区切り文字の位置を探す。
区切り文字間の単語を拾い出し、それぞれの数を数える。
これをデータの終わり'File end'まで繰り返す。
Fortranの文法文字処理を参照。