[ create a new paste ] login | about

Link: http://codepad.org/wKheIc4l    [ raw code | output | fork ]

C, pasted on Jul 6:
#include<stdio.h>
#include<string.h>

char word[5][11] = {"library","follow","enter","common","practice"}; /* 出題される単語 */
char inp[11]; /* 入力 */
int miss[128]; /* ミスしたスペルを格納*/

int main(void){
  int weak=0;
  int i,j;
  int good = 0; /* 正解 */
  int bad = 0; /* 不正解 */
  float rate = 0.0; /* 単語単位の正解率 */

  printf("今から出題される英単語をタイプしてください。\n");
  
  for(i=0;i<5;i++){
    printf("問%d.「%s」:",i+1,word[i]);
    scanf("%s",inp); /* タイピングしたものをinpに配列 */
    if(strcmp(inp,word[i])==0){  /* 正解と一致 */
      good++; /* 正解を加算 */
    }else{
      bad ++; /* 不正解を加算 */
      for(j=0;word[i][j];j++){ /* 1文字ずつ比較し、初めのミスまでループ */
	if(inp[j] != word[i][j]){ /* ミスタイプしたら */
	  printf("%c\n",word[i][j]); 
	  miss[word[i][j]]++; /*  その文字をカウントしていく*/
	  break;
	}
      }  
    }
  }
  for(i=0;i<128;i++){
    if(miss[i]>miss[weak]){ /* 間違えた回数が一番多かったキーを求める*/
      weak = i;  
    }
  }
  rate += 100*(float)bad/((float)good + (float)bad); /* 単語単位正誤率 */
  printf("good 「%d問」 bad 「%d問」 weak key「%cキー」 単語単位の正誤率 「%.2f%」 \n",good,bad,weak,rate);
  return 0;  
}


Output:
1
2
3
4
5
6
7
今から出題される英単語をタイプしてください。
問1.「library」:l
問2.「follow」:f
問3.「enter」:e
問4.「common」:c
問5.「practice」:p
good 「0問」 bad 「5問」 weak key「cキー」 単語単位の正誤率 「100.00%」 


Create a new paste based on this one


Comments: