fork download
  1. program hash_example
  2. implicit none
  3. character(len=20) :: student_id, name
  4. character(len=40) :: combined_string
  5. integer :: i, hash_value
  6.  
  7. ! 1. 入力
  8. print *, "学籍番号を入力してください:"
  9. read(*, '(A)') student_id
  10. print *, "氏名を入力してください:"
  11. read(*, '(A)') name
  12.  
  13. ! 2. 連結 (trimで余分な空白を除去)
  14. combined_string = trim(student_id) // trim(name)
  15. print *, "連結された文字列: ", trim(combined_string)
  16.  
  17. ! 3. 簡易ハッシュ計算 (各文字のASCIIコードの合計を求める例)
  18. hash_value = 0
  19. do i = 1, len_trim(combined_string)
  20. hash_value = hash_value + ichar(combined_string(i:i))
  21. end do
  22.  
  23. ! 4. 結果表示
  24. print *, "計算された簡易ハッシュ値: ", hash_value
  25.  
  26. end program hash_example
Success #stdin #stdout 0s 5320KB
stdin
202400688
齋藤蓮
stdout
 学籍番号を入力してください:
 氏名を入力してください:
 連結された文字列: 202400688齋藤蓮
 計算された簡易ハッシュ値:         2123