------------------------------------------------------
AC代码:
1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 7 Scanner sc=new Scanner(System.in); 8 9 int times=Integer.parseInt(sc.nextLine()); 10 11 while(times-->0){ 12 13 String s=sc.nextLine(); 14 StringBuilder sb=new StringBuilder(s.length()*2); 15 int ans=0; int continuout=1; 16 for(int i=0;i<s.length();i++){ 17 char c=s.charAt(i); 18 if(c=='O'){ 19 sb.append(continuout); 20 ans+=continuout++; 21 }else{ 22 continuout=1; 23 sb.append("0"); 24 } 25 if(i!=s.length()-1) sb.append("+"); 26 } 27 System.out.printf("%s=%d\n",sb.toString(),ans); 28 } 29 30 } 31 32 }