douxuan0698 2015-05-20 11:31
浏览 45
已采纳

查找符合特定要求的字符串

There is a function that should return true:

func accessible(agent string) bool {
  a := strings.Split(agent, " ")
  if len(a) != 3 { return false }
  b := a[0]
  c := a[1]
  d := a[2]
  x := strings.EqualFold(b, c)
  y := b != strings.ToLower(c)
  z := strings.Index(d, b+c) == 1 && len(d) == 5
  return x && y && z
}

However I can't figure out which string input will match these requirements. Am I missing something?

PS: This is task #3 from gocode.io

  • 写回答

1条回答 默认 最新

  • duanqianpu6499 2015-05-20 11:38
    关注

    agent must be 3 "words", 3 parts separated by spaces:

    a := strings.Split(agent, " ")
    if len(a) != 3 { return false }
    

    1st and 2nd words must match case insensitive:

    x := strings.EqualFold(b, c)
    

    But not case sensitive:

    y := b != strings.ToLower(c)
    

    And 3rd word must contain the first 2 concatenated:

    z := strings.Index(d, b+c) == 1 && len(d) == 5
    

    Starting at index 1 (prepend with any character) and must contain 5 chars (5 bytes) (postpend to have 5 chars/bytes).

    Example:

    fmt.Println(accessible("A a _Aa__"))
    

    Prints:

    true
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算