编程介的小学生 2017-03-10 02:31 采纳率: 20.5%
浏览 830
已采纳

AB Circle

A circle formed by 'a' and 'b', you are required to figure out all such pairs of positions that when cutting the circle in a pair of the positions, we will get two segments that the number of 'a's in one segment is equal to the number of 'b's in the other segment.

Input

The length of circle: n is between 2 and 1000 inclusive.

All the characters in the input is either 'a' or 'b'.

There is no strings without any 'a' in the input.

There is no strings without any 'b' in the input.

Output

There are no more than 400 test cases. For each test case, print out all the correct cuttings. For each cutting, print out a pair of integers, representing the two positions to cut on.

In output, all the pairs of positions should be sorted.

The llegal positions' number is between 0 and n-1 inclusive.

Print a blank line after each test case.

Sample Input

ab
baa

Sample Output

AB Circle #1:
0,1

AB Circle #2:
0,1
0,2
1,2

Note for sample 2

original: baa
cut in 0,1:
b aa
the number of 'a's in "b" = the number of 'b's in "aa" = 0
cut in 0,2:
ba a
the number of 'b's in "ba" = the number of 'a's in "a" = 1
cut in 1,2:
a ab
the number of 'a's in "a" = the number of 'b's in "ab" = 1

  • 写回答

1条回答 默认 最新

  • devmiao 2017-03-10 23:12
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)