当前位置: 首页 > 知识库问答 >
问题:

需要更多的澄清序列变换的挑战Codeeval

惠志
2023-03-14

挑战描述:

有两个序列。第一个序列由数字“0”和“1”组成,第二个序列由字母“A”和“B”组成。挑战在于确定是否可以使用以下规则将给定的二进制序列转换为字符串序列:1。“0”可以转换为字母“A”(“A”、“AA”、“AAA”等)2的非空序列。“1”可以转换为非空的字母序列“A”(“A”、“AA”、“AAA”等)或非空的字母序列“B”(“B”、“BB”、“BBB”等)。

对于每个测试用例,如果转换是可能的,打印“是”,否则打印“否”。例如。

 1010 AAAAABBBBAAAA 
 00 AAAAAA
 01001110 AAAABAAABBBBBBAAAAAAA
 1100110 BBAABABBA
Yes
Yes
Yes
No

规则1:a^n<-(0)规则2:(a/b)^n<-(1)

使用这个逻辑,如果我求解给定的例子,我将分别得到是和否,这满足了例子。

例1:

    null
    null
import sys
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
  digits, word = test.split()
  seq = None
  result = None
  count  = 0
  word = word[::-1]
  digits = digits[::-1]
  for character in word:
    #print character, seq, count, digits, digits[count]
    if not seq:
      seq = character
      continue
    if seq != character:
        if seq == 'B' and digits[count] == '0':
          result = "No"
          break
        seq = character
        count+=1
  if result:
    print result
  else:
    print "Yes"

test_cases.close()
0000 AAA
Yes
111111000111001110001110101100100 AABBBBBBBBBBBAAAAAAAAAAAAAAABBBBBBBAAAAAAAAABBBAAABBBBBAAAAAAAAAAAAABBBBAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAA
No
1101110110011101000010101110110101000100011110001101010001 BBBBAABAABBAAAAAABABBBBBBAAAAAAAABAABAABBBABBAAABBBBBBBABBBBAAAAABBBABBBAABBA
No
0100011111110101101000100010011101010111110111101011000110111111100101011011101010111100101000010011110 AABAAAAAABAABBBBABAABAAAAABBBAABAAAAABABAABABBBBBAABBBAAABABBABAAABBABBABAABAABABBBBBAAAABAABABAAAABBBAAABA
No
000001010111001000110010000111101111000100000110011000010011000010110010101111110110111101111100101 BBABBBAAABABBAAABBABBBBAABBBBAAAAABAABBAABABBABABABBAAAABBAAAAAAAAAAAABBBAABAAABABAABAAAAABBABBBABBBA
No
1 B
Yes
00010000100010000111011110110001111001110110101000100010111110010 BBBABABABBABBAAABBBBABBBABBABABABBBAAABBAAABBBBABABBAABBBAAAABBBB
No
10 BBBBBAAAAAAA
Yes
10100000010110110100001011000011100000100010100001110 BBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAABBBAAABBBBBBAAABBAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAABBAAAAAAAAAAAAAAAAAABBBAAAAAAA
No
1111111000100100000110011110 AAAAAAABBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBAAAAAAAAAAAABBBBBBBABAAA
No
000000101 AABBBABABAAAABABBBB
No
1000110111100110100000110111010100101011111100110001111000101100001 BBAAAAAAAAAAABBBBBBAAAAAAAAAABBBAAAAAABAAAAAAAAAAAAAAAAABBAAAAAAAAAAAAAAAAAAAAABBAAAAAABBBAAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBAAAAAAAAAAAAABBBAAAAAAAAAAABBBBBBBBBBBBAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAB
No
00111011000111010101100001 AAAAAAABBBAAAAAAAAABBBBBBAAAAAAAAAAAAAAABBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB
No
010000101110000010110011001000110010000110111110101100100000011101011100100110001000000111100010010100011011100 ABBABAAABAABBAAAABBBAABAABABABBAAABBBAABBBABBAAAABAABABBBABABBAABABABBAABBABBBABBBBABBBABBBAABABBABAAABAAAAAABBBABA
No
000011 AAAAAAAAAAAAAAAAAAABBBBB
Yes
00110 AAAABBAA
Yes
1110011111001001110011001011100000110110001101000000100110101010000001101100010100001111011110110000100111000001100101001101100110011 BAABBBABABABBABAABBBBBBAABABAAAAAABBABBBBAAAAABABABABABAABABBAAAABBAABBAAABBBAAABABBBBBABBBABBAAABBABAAABBBBAAAABAAAAABBAABABABBBBBBABBBBBABABABABABBBAAAAAABABBBAAABBBBAABABABAABBBBBABAABBAABABBBAAABABBBBBBABA
No
01001111101000000001001110001100100011100011000010100011110111101111011010110101100001011001111101011100100011101010100011111 AAABAAAAAAABBBAAAAABBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAAAAAAABBBBBBAAAAAAAAAAABBBAAAAAAAAAAAAAAAAAAAAABAAAAABBBBBAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAABBBBBBBBBAAAAAABBBAAAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAABBBBBBBBBBAAAAAAAAABBBBBBBAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAABBBBBAAAABBBBBBAAAAAABBBAAAAAAABBAAAAAAAAAAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAABBAABBBAAAAABBBAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBA
No
11001000011111000111001001110011000001100101 BBBBBBAAAAAAAAABAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAABBBBAABBBBBBAAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAB
No
1011100100010011110000111111111100101001010000011000011111001010111001011101010100000000 ABABAABABABABBAABABBBABABBBBABBAAABBBBABAAABABABBBABAAABAABBBAABAAAABBAAABBBBAAABAABABAABAAABBBBBABBBAA
No
10101100101000110 AABBBAAAABBAAAABABBBAABAABABAAAAAAABAABABAABBBBAAAAA
No
11010101101010010011000011100110011110101000001111010000000101010011001011111001000010101010110000000110100101100100110101000 AAAAAABBBBAAAAABBAAABBBAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAABBBBBBBAAAAAAAAAAABBBBBAAAAAAAAAAAAAABBBBBBAAAAAAABBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAABAAABBBBBBAAAAAAAABBBBBAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBAAAAAABBBBAAAAAAAAAAAAAABBAAAABBBAAAABBBAAAAAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBAAAAAAAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAAAAAAAAAAAAA
No
01 BBBBBAAAAAAA
Yes
1 BBBBBBAAAAAA
Yes
010111001100101011001101010010011111000101011111111000100000010010011101010011010011101101000000000000010111111010100110110101000101 AAAAAAAAAAAAAAABBBAAAAAAAAAABBBBBBBBBBAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAAAAAAAABBBBAAAAABBAAAAAAABBBBBBAAAAABBBAAAAAABBBBAAAAAAAAAAAAAAAAAAAAAABBBAAAAAAAAAAAAAAAAAABBBBBAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAABBBBAAAAAAABBBBBBAAAAAAABBAAABBBBAAAAAAAAAAAAABBBBAAAAAABBBBAAAAAABBBBAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBAAAAABBAAAAAABBBBAAAAAABAAAAAABBBBAAAAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAABBAABBBBBAAAAAAAAABBBBBAAAAAA
No
0111011101011001110011000011110100100 ABBABBABABBABABABAABBBAAABAABBAAAAABAAABAAABABBBABABBBAAABAB
No
110101010100100111101010111011100011010001010110011111000011001011101110100011001111100001111111 BAAABABAAABBBBAAABAABBBABBBAABBBBAAAABABAAABAAAAABBAAAAABBBBBAAABABAAABBABABAABABAABAABBBBAAABBABBABB
No
11101111000011101110101001100110111011110101011100000010001100011110100111111100110010111011100001101011101110110100100 ABAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAAAAABAAAAAAAAAAAAAAABBBBBBAAAAAAAAAABBBBAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAABBAABBBBAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBAAAAAAAAAAABBBAAAAAAAAAAAAABBBBBAAAAAABBBBBBAABBBBBBBBBBBBAAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBAAAABBBAAAABBBAAAAAABBBAAAAABBAAAAAABBBBBBAAAAAAAAAAAABBBAA
No
0111100001110101011101001110001101101010011100110100001011011010011101001000110000111110110100001010011001101110001 BAAABBAABBBBABBBBABABABBABABABAAAAAAAAAAAAAABBBAAABBABAAAABBAAABBBAABAAABABAAAABBABBABABBABAABBAABBBABBAAAAAAAABABBBBBAB
No
001010111001000001000101111100001100111011010100000010010010100101011011010110010110000 ABBAABBAAAAAAABABBAABBBABBAAABBABABABBAABABABAABAABAAABBAAABAABBAAAABBABBABBBAAAAAABABBBBAAABAABABAAABAABAAAAABBBBBABBBABBAABAABBBABBBBABAAABABBAAABBABA
No
001001001010100001101011111000001000100100000000011001001111001010001101 AAAAABAAAAAAAAAAAAAAAAABAAAABBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBAAAABAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB
No
00010010101110000100101 BBBAAAAABABABBAAAAABBBA
No
001011010111001010100011101011100000000000110110110101110001110110110010010100 AAAAAAAABBBBBBAAAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAABBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBAAAAAAABBBBBBABBBBBBAAAAABAAAABBAAAAABBBBBBAAAAAAAAAAAAAAAABBBBAAAAABBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
No
00010101011100100000 AAAAAAABABBBBAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBAAAAAAAAAAAAAAA
No
0001001000000011 BAAABBBBBABABAAAABBBBBBBBBBAAAAAAABBBAABAABABABBB
No
00100010101001011111101011010110010111001100010000001001011101101001110000001100110010101101111000111101010001101 BABBBBABAAABAAAABABBABBBAAAAABBAAABBBBAABABBBAAAAAABABBABABBBBBAABBBBBBAAAABABABABAAABAAAABABAABAABAABBABBBAAABABAAAAAAABAAABAAAAABAAABBBBBBBBAABABABBBAABAAAAAAAABABBAABBBABBBABBABBBB
No
01010011101101010010000000110101010000100011010000011101100111010101101100111001100 AABBAAABABABBBBBBBBBBAABBBBABAAABABAAABABAABABAAAAABABBABABABBBAABBAABBBBAABBBAAAAAABBAABBABAABBBBBAAAAABBBAAAABABBBAA
No
0 A
Yes
101001010101 BBBBAABAABAABBAAAABAABABBAABABBBBABABBAABABABAABBBBBBBAABAABBAABAABBAAAABABABAABABABABBABAAABBBABA
No
000011111010110010100000011101001110110101001111110101001110110101100000100001100011011010011000001010101111101010010100011010111011011001 AAAAAAAAAAAAAAAAAAABAAABBBBBAAAAAAAABBAAABBBAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBAAAAAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAAAAAABAAAAAAAAAAAABBBBABBBBBBAAAAAAAAAAAAAABBBBBAAAAAAAAAAAAABAABAAAAAAAAAAAAAAAAABBBAAAAAAAAAAAAAAAAAAAAABBBAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBAAAAABAAAAAAAAAABBBAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAAABBBAAAAAAAABBBBBBAAAAAABBBBAAABAAAAAAAAAABBBBAAAABAAAAAAAAABBBBBB
No
1110010000010010001100101010011010101 BBBABBBAAAABAAAABBBAAAAABAAAAABABAAAA
No
00100101101111100001000110110111010100110111100001101101011101100100001100111 ABBAABABABABAABBAABBBBBAABABBABBAABBBBAAAABAAABBABBBABAABBBBBBABAAAABBAABAAAABBAA
No
001110010101100010111010111000001010100101011110000011110101011110100011011100010111011110 AAAAAAAAAABAAAAAAAAAABAABBBAAAAABBBAAAAAAAAAAAAAAAAAAAABBBBBAAABABBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAABBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAABBBBBBBAAABAABBAAAABBBBBAAAABBBBBABBBBBBBAABBBAAAAAAAAAAABBAAAAAAAAABBBBBAAAAAAAAAAAAAAAABBBBBBAAAAAAAAAAAAAABBBBAAAAAAAAAAAAAAAAAAAAABBBBBBAAAA
No
0000 AAAA
Yes
1100100011011000110101110110011100001101110000101111101110111011100010101010110100000110100110110010000101001101110110110101111010101100110 BBBAABBBABAABBABBAABBBAAAAAAAABBBABABBABABBBBAABBBBBAABAABBABAAABBABBABABBBABBABBBABAABBAABABAAAABABBABBBABAABAAABBABABAAAAABBBAAABABBABBAABBBAABABABBAAABAABAABBAAAAABBAABBAAABBABBBAABAABAB
No
000001000101110010110000100111100111001110110101110100001000001011111001001010010001111110000100011011010000110011010011010110 AABBAABBABBAAABAAABABAAAABBABAAABBAAABBAABBABAABABAABBBBBAABBAAABBAABAAABABABABAABAABAABABAAAABBBAAABBBBBBAAABAAAABABBAABBABBA
No
1011000100010001010010111100100011100101000001010010010011001100100011000001111000011000001100011001101000110010010010101011100010001110010 ABABBABAAABAABBAABBBBBABABBBBBBAABAAAAAAABBBAABBABAAAAAAAAABABAABABBAAAAAAABABBAAAABBBBBBBBBABBABBBABAABAABAABBBABBAABBBBAAAABAABBBBBBBBAAB
No
110011011010101110010010100110010010110011111000100011011101110000110111 AABABABBABBAABBABBABAAAABBBAABBBBBBBABABBBBBABABABBBAAABABBABABBABAABBBBABABB
No
01001 ABBBAB
No
00010110110 BABABBAABAABABBBABABABBABBABB
No 

共有1个答案

伏欣悦
2023-03-14

1匹配一个或多个元素,AB

您的理解在这里是不正确的,因为您似乎认为匹配0次也是有效的:

  1. 1010 aaaaabbbbaaa-是
  2. 无<-(1)AAAAA<-(0)BBBB<-(1)AAAA<-(0)
    null
0000 AAA
 类似资料:
  • 需求:创建一个多租户应用程序,该应用程序应该根据请求中的租户id将每个租户的数据插入到各自的PDB中。换句话说,每个租户或客户在CDB中都有自己的PDB,所有PDB都有相同的模式,然后根据请求中的租户Id选择一个数据源,并将数据插入到该PDB中。 Stack-Spring boot 2.3.0.发行版,Oracle 18c,连接池-Oracle共享通用连接池 UCP连接: Spring数据源配置类

  • 我认为用A*算法应该是SAEFG,但答案是SBEFG。现在我的教授是一个无所事事的人。有人能解释为什么是SBEFG吗?

  • 来自 https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#poison 当 Blob 触发器函数失败时... “失败”是什么意思?编译失败?引发未处理的异常? 如果有一些不起作用的示例代码,那就太好了。所有示例代码都显示了工作状态,因此无法演示 Azure 函数中的故障模式。

  • 我们有申报单 其中backlog被标识为传入连接的最大队列长度。如果连接指示在队列已满时到达,则会拒绝连接。 假设积压设置为10。 这是否意味着服务器套接字将接受不超过10个客户端? 然后: 只有当时,积压数才会下降。这是正确的吗? 有没有办法知道一个套接字当前正在处理多少个打开的连接(换句话说,它离放弃并开始拒绝新连接有多近)

  • 现在,编辑器在使用注释方法的地方显示警告。然后显示使用的建议。当我接受它的更改时,它会将代码转换为此,警告消失。 使用有意义吗? 实现是 所以如果为空,我的代码仍然会崩溃。 我们应该对此进行空检查。 我认为比好,你说呢?如果是,则编辑器不应建议在此处使用。 因为在具有状态(如)的字段中使用要求NonNull是不安全的。我是否错过了的一些好处?

  • 我需要一些帮助来澄清写关注的概念,我使用MongoDb 4.0.2(带副本集)和java-mongo驱动程序3.8.1 我已经在mongo配置中添加了关于 在代码端,何时可以使用数据库的ack响应?我发现,当使用delete或update时,库返回一个Result对象(作为deletesult),其中包含一个函数,用于获取集合中多数副本的delete/update结果。 但是我找不到一个类似的所有