- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在研究以下CodeChef question :
Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example letters "A", "D", "O", "P", "R" divide the plane into two regions so we say these letters each have one hole. Similarly, letter "B" has two holes and letters such as "C", "E", "F", "K" have no holes. We say that the number of holes in the text is equal to the total number of holes in the letters of the text. Help Chef to determine how many holes are in the text.
Input
The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input.
Output
For each test case, output a single line containing the number of holes in the corresponding text.
Example
Input:
2
CODECHEF
DRINKEATCODEOutput:
2
5
我正在提交以下代码,但法官一直显示错误答案(WA)。有什么建议吗?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class test {
static short[] srr=new short[41];
public static short getHoles(String st){
short holes=0;
for (int i = 0; i < st.length(); i++) {
char c= st.charAt(i);
if(c=='A') holes++;
if(c=='D') holes++;
if(c=='P') holes++;
if(c=='O') holes++;
if(c=='R') holes++;
if(c=='Q') holes++;
if(c=='B'){
holes++;
holes++;
}
}
return holes;
}
public static void main(String[] args) throws IOException {
BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
short cases;
String stt= s.readLine();
cases=Short.parseShort(stt);
String temp;
short t;
for (int i = 0; i < cases; i++) {
temp=s.readLine();
t = getHoles(temp);
srr[i]=t;
}
for (int i = 0; i< 45; i++) {
if(srr[i]==0) break;
System.out.println(srr[i]);
}
}
}
最佳答案
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Letter {
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
InputStreamReader is= new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(is);
int n= Integer.parseInt(br.readLine());
for(int i=0;i<n;i++) {
int holes=0;
String s= br.readLine();
char[] ch= s.toCharArray();
for(int j=0;j<ch.length;j++) {
if(ch[j]=='A'||ch[j]=='D'||ch[j]=='O'||ch[j]=='Q'||ch[j]=='P'||ch[j]=='R') {
holes= holes+1;
}
else if(ch[j]=='B') {
holes=holes+2;
}
else {
holes=holes+0;
}
}
System.out.println(holes);
}
}
}
关于java - 代码厨师 : Holes in the Text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34745395/
我最近继承了一个数据库,其中一个表的主键由编码值 (Part1*1000 + Part2) 组成。 我对该列进行了标准化,但无法更改旧值。 所以现在我有 select ID from table or
有没有人有一个使用 Delaunay 填充网格的直接 Delphi 示例三角形还是克里格法?任何一种方法都可以通过“插值”来填充网格。 我想做什么?我有一个网格,类似于: 22 23 xx 17
如果满足条件,我需要从数组中删除一些对象。 从数组中删除对象后,我需要数组没有“空洞”,这意味着我需要缩小数组:不是数组大小,而是减少它包含的对象数量。 删除对象后如果数组末尾有空值也没关系。 哪个效
我有一个像这样的二维数组(它代表一个时间表): alt text http://www.shrani.si/f/28/L6/37YvFye/timetable.png 橙色单元格是讲座,白色单元格是空
我正在创建一个包含 2 层的页面:一个图像层和一个位于其顶部的半透明“ mask ”层。我想在该蒙版中动态放置一个小矩形“孔”,以便可以在该区域看到其下方的原始图像。 这可能吗? 最终目的 a 是创建
我有一个姓名和电话号码列表,如下所示: var phonelist = List { new string[] {"Bill", "1234", "12345", "12314" },
我有星系的照片图像。这些图像上有一些不需要的数据(如星星或飞机条纹)被屏蔽掉了。我不只是想用一些平均值填充屏蔽区域,而是根据周围的数据对它们进行插值。我如何在 python 中做到这一点? 我们尝试了
我正在尝试使用 SVG 路径元素来定义带有“孔”的区域。我想使用这些区域来突出显示图像中的某些文字。 我的目标是展示使用 OCR ( Google Cloud Vision API) 从图像中提取文本
给出下表: create table #Track (id int identity, vehicle int, station varchar(50), pieces int, distance i
假设您有一组日期范围 var arr = [ { "from": 'unix 1st of august', "until": 'unix 5th of august' },
这是我的 code : HTML text under link! CSS .myDiv { position:relative;
我正在研究以下CodeChef question : Chef wrote some text on a piece of paper and now he wants to know how man
识别完全被 1 包围的 0(不需要对角线覆盖)。在下面的示例中,大小应为 3。 二维数组中可能有任意数量的“孔”。 [[1,0,1,1], [1,1,1,1], [1,0,0,1], [1,0,
考虑一个 MxN 位图,其中单元格为 0 或 1。“1”表示填充,“0”表示空。 找出位图中“孔”的数量,其中孔是空白单元格的连续区域。 例如,这有两个洞: 11111 10101 10101
我将如何着手在 Windows 窗体中创建一个动态“孔”,用户可以通过它看到实际的桌面而不是窗体?现在,我已经在整个屏幕的顶部创建了一个半透明窗体,我希望透过该半透明窗体进行查看。 最佳答案 使用表单
我已经阅读了一些关于此的帖子,但没有一篇涉及此问题。 我想这是不可能的,但我还是会问。 我有一个包含 50.000 多个寄存器的表。这是一张旧表,其中发生了各种插入/删除操作。 也就是说,大约 300
首先:我知道,这个问题在这里已经有很多答案了,但是他们并没有帮助我解决这个问题。 我编写了一个小游戏。在第一次发布时有一个小教程,其中一点一点地解释了游戏的每个元素。在每一步中,我都想强调这些元素之一
谁能告诉我为什么我的网格布局中可能会有看似随机的“漏洞”?我正在使用 Zurb Foundation。 尽管这是一个基本的网格布局,但有些列会无缘无故地向右浮动。看起来好像偶尔缺少一篇文章,但如果您查
有没有一种方法可以提取或显示孔洞,同时丢弃外部轮廓? 我可以使用 CV_RETR_EXTERNAL 仅显示外部轮廓,但似乎无法仅显示内部轮廓(孔)。 最佳答案 你可以在 C 接口(interface)
当我删除时,例如,id 3,我有这个: id | name 1 | 2 | 4 | 5 | ... 现在,我想搜索丢失的 ID,因为我想用以下内容再次填充 ID: INSERT INT
我是一名优秀的程序员,十分优秀!