编程介的小学生 2017-04-29 16:21 采纳率: 20.3%
浏览 879
已采纳

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
BE CAREFULL: the total size of output might be very large.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失