丑陋的字符串2
来源:互联网 发布:linux sed 举例 编辑:程序博客网 时间:2024/04/30 12:53
import java.util.Scanner;
public class 丑陋的字符串 {
public static void main(String[] args) {
Scanner sr = new Scanner(System.in); String s = sr.next(); StringBuilder sb = new StringBuilder(s); int index = 0; while(index<sb.length() && sb.charAt(index)=='?'){ index++; } for(int i=index+1;i<sb.length();i++){ if(sb.charAt(i)=='?'){ if(sb.charAt(i-1)=='A') sb.replace(i, i+1, "B"); else sb.replace(i, i+1, "A"); } } System.out.println(count(sb.toString(),index));}private static int count(String str, int index) { int count = 0; for(int i=index+1;i<str.length();i++){ if(str.charAt(i) == str.charAt(i-1)) count++; } return count;}
}
阅读全文
0 0
- 丑陋的字符串2
- 丑陋的字符串
- 丑陋的字符串
- 丑陋的字符串
- 【算法题】丑陋的字符串
- 【编程题】 丑陋的字符串
- [编程题] 丑陋的字符串
- 【编程题】 丑陋的字符串
- 丑陋的面具
- 丑陋的263
- 所谓的丑陋
- 读丑陋的中国人
- 丑陋的中国人
- 《丑陋的中国人》
- 丑陋的自己
- 丑陋的中国人
- 规避丑陋的eval
- “丑陋”的贪吃蛇
- AJAX-简单示例
- day08
- 8月2日训练
- 组件化架构漫谈
- 机器学习教程之13-决策树(decision tree)的sklearn实现
- 丑陋的字符串2
- Lucene&&Solr中的域(Filed)总结
- TabLayout、ViewPager和Fragment之间的通讯
- [LeetCode]104. Maximum Depth of Binary Tree--二叉树的最大深度
- 微信小程序之一本地图片处理--按屏幕尺寸插入图片
- ZigBee协议栈简介和流程
- Python package安装指南
- C++之通过符合塑模出has-a或“根据某物实现出”(38)---《Effective C++》
- OpenStack学习笔记-2