#!/usr/bin/env ruby
# coding: utf-8

require 'cgi'
c = CGI.new(:accept_charset => "UTF-8")
print "Content-type: text/html; charset=UTF-8\n\n"

n_quest = c["n_questions"].to_i

print"<html>
<head><title>テスト結果</title></head>
<body>\n"
print "<h23>テスト結果</h2>"

correct = 0
for i in 1..n_quest
  q = c["q#{i}"]
  printf("<p><strong>%s</strong></p>\n", q)
  usr_ans = c["usr_ans#{i}"]
  corr_ans = c["corr_ans#{i}"]
  if usr_ans == corr_ans
    correct += 1
    print "<p><span style=\"color: green\">正解</span><br>\n"
  else
    print "<p><span style=\"color: red\">不正解</span><br>\n"
    printf("正解は %s です</p>\n", c["full_corr_ans#{i}"])
  end
end


printf("<p>Score: %d/%d</p>\n",correct, n_quest)
print"</body>\n"
print"</html>\n"
