eec8835387629fd0364f0bbab559e887dc6dfac5.svn-base 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package main
  2. import (
  3. "fmt"
  4. "math"
  5. "strconv"
  6. )
  7. func main(){
  8. a := []int{1,2,3}
  9. //b := []int{4,4,4}
  10. b := make([]int,3)
  11. copy(b,a)
  12. test(b)
  13. fmt.Println(b)
  14. s := "({{[wqeyqebA"
  15. for _, value := range s {
  16. //println(value)
  17. if value == 's' {
  18. }
  19. //println(string(value))
  20. }
  21. c := 'B'-1
  22. e := math.Pow(2,3)
  23. //println(string(s[2]))
  24. fmt.Println("======",'A','B',c,e)
  25. f,err :=strconv.ParseFloat("2d2",64)
  26. if err != nil {
  27. fmt.Println("--wwdd",err)
  28. }
  29. fmt.Println("--dd",f)
  30. //w :=titleToNumber("ABC")
  31. //fmt.Println("================",w)
  32. res := []string{"ffffffflowwew","ffffffflsrrww","ffffffflswee"}
  33. t :=longestCommonPrefix(res)
  34. fmt.Println(t)
  35. }
  36. func test(a []int){
  37. b := a
  38. b[1]= 1
  39. }
  40. func titleToNumber(columnTitle string) int {
  41. l := len(columnTitle)
  42. if l == 0 {
  43. return 0
  44. }
  45. res := 0
  46. for i:= 0;i<l;i++{
  47. m := int(math.Pow(26,float64(l-i-1)))
  48. println(m)
  49. res = res + int(columnTitle[i]-64)*m
  50. }
  51. return res
  52. }
  53. func longestCommonPrefix(strs []string) string {
  54. res := ""
  55. for i:=0;i<=200;i++{
  56. var tem byte
  57. ist := true
  58. for k,str := range strs{
  59. if len(str)<i-1{
  60. return res
  61. }
  62. if k == 0{
  63. if len(str) == 0{
  64. return ""
  65. }
  66. if len(str)<i-1{
  67. return res
  68. }
  69. tem = str[i]
  70. }
  71. if str[i] != tem{
  72. ist = false
  73. }
  74. }
  75. if ist{
  76. res = res +string(tem)
  77. }else {
  78. return res
  79. }
  80. }
  81. return res
  82. }