题解 | 小苯的ovo2.0

小苯的ovo2.0

https://www.nowcoder.com/practice/e9745dcd7c534bc4beda0f7ee13addca

import java.util.*;

public class Main{
    static Scanner in = new Scanner(System.in);
    static long cal(String s){
        long a = 0;
        long b = 0;
        long res = 0;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == 'o'){
                a ++;
                res += b;
            }
            else{
                b += a;
            }
        }
        return res;
    }
    static void solve(){
        String s = in.nextLine();
        int n = s.length();
        int[] v = new int[n+5];
        int cnt = 0;
        for(int i = 0; i < n; i++)
            if(s.charAt(i) == '?'){
                v[++cnt] = i;
                s = s.substring(0, i) + "o" + s.substring(i+1);
            }
        long ans = cal(s);
        for(int i = 1; i <= cnt ; i ++){
            String s1 = s;
            for(int j = i; j <= cnt; j ++){
                s1 = s1.substring(0,v[j]) + "v" + s1.substring(v[j]+1);
                ans = Math.max(ans, cal(s1));
            }
        }
        System.out.println(ans);
    }
    public static void main(String[] args){
        int T = in.nextInt();
        String ss = in.nextLine();
        while(T-- > 0) solve();
    }
}

全部评论
还有第二关
点赞 回复 分享
发布于 03-30 15:32 河北

相关推荐

不愿透露姓名的神秘牛友
03-20 22:18
FightingNa...:小厂不喜欢离毕业还远的。培养你三个月小半年,你又回去上学,你丰富简历爽歪歪,小厂啥也得不到。大厂兴许愿意培养你,可以试试大厂,准备下不黑了就行。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务