fork download
  1. // Safaa_Eek 305073363 Enas_Bisharat 200686129
  2. package main
  3.  
  4. import (
  5. "fmt"
  6. )
  7.  
  8. //we define an array of elems, each elem is a struct and has two fields:
  9. //one for the letter and the second is for the instances.
  10. type elem struct {
  11. index byte
  12. n int
  13. }
  14.  
  15. //this function recieve "byte"(a letter)and return the lower case of the letter
  16. func ToLower( c byte) byte{
  17. if c >= 'A' && c<='Z'{
  18. return c-'A'+'a'
  19. }
  20. return c
  21. }
  22.  
  23. //this function recieve "byte"(a letter)and return the upper case of the letter
  24. func ToUpper( c byte) byte{
  25. if c >= 'a' && c<='z'{
  26. return c-'a'+'A'
  27. }
  28. return c
  29.  
  30. }
  31.  
  32.  
  33.  
  34. func main() {
  35. var c byte
  36. var count [26]elem
  37. var temp elem
  38.  
  39. //define the array of elems, the index field has the letter,(sorted
  40. //from a to z) and the instances field is 0 at the beggining and then
  41. //it will be the number of the instances of each letter
  42. for i := 0; i<26; i++ {
  43. count[i].index = byte('a'+i)
  44. count[i].n = 0
  45. }
  46.  
  47. //recieve letters until "enter" is recieved for the first time
  48. for {
  49. fmt.Scanf("%c",&c)
  50. if c == '\n' { break }
  51. c = ToLower(c)
  52. //get the lower case of the letter and we see if it is legal
  53. //(between a and z)
  54. if c>='a' && c<='z' {
  55. //update our array in the right place.. we add 1 the instances field
  56. count[c-'a'].n +=1
  57.  
  58. }
  59. }
  60.  
  61. //and now we sort our array, by finding the maximum in each iteration
  62. //and put it in the right place (replace elems)
  63. for i:=0; i<26 ; i++ {
  64. for j:=i+1; j<26 ; j++{
  65. if count[i].n < count[j].n {
  66. temp = count[i]
  67. count[i]=count[j]
  68. count[j]=temp
  69. }
  70. }
  71. }
  72. //print the unempty places in our array(the letters that have been recieved)
  73. for i:=0 ; i<26 ; i++ {
  74. if count[i].n != 0{
  75. fmt.Println(string(count[i].index), "/",string(ToUpper(count[i].index)),
  76. " ", count[i].n)
  77. }
  78. }
  79. }
  80.  
Time limit exceeded #stdin #stdout 5s 3120KB
stdin
aabbggg654$$
stdout
Standard output is empty