×

# Holes in a string

 0 Count the holes if D,O,P,Q,A have 1 hole and B has 2 hole input word: BABOY output:6 holes This question is marked "community wiki". asked 21 Feb '13, 19:28 0★cris18 1●2●2●2 accept rate: 0% 2.3k●18●30●69 R has no holes? :/ R should have 1 hole as well. My code includes that. (21 Feb '13, 23:31)

 2 @cris18 traverse the string and do follows: int main() { char st[100]; scanf("%s",st); int l = strlen(st); for(int i=0; i
 0 @cris18 traverse the string and do follows: int main() { char st[100]; scanf("%s",st); int l = strlen(st); for(int i=0; i
 0 Just timepass ;) #include #include #include using namespace std; int holes[26] = {1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; int main() { char s[100]; cin>>s; int len = strlen(s); int hcount = 0; for(int i=0; i
 0 Here is the Java solution you seem to need. public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) ); BufferedWriter out = new BufferedWriter( new OutputStreamWriter( System.out ) ): String s = in.readLine(); // Accepts the word as input. int count = 0; for( int i = 0; i < s.length(); i++ ) { // Checks if the character has one hole. R also has a hole. if( s.charAt( i ) == 'D' || s.charAt( i ) == 'O' || s.charAt( i ) == 'P' || s.charAt( i ) == 'Q' || s.charAt( i ) == 'A' |} s.charAt( i ) == 'R' )) count++; // Checks if the character has two holes. else if ( s.charAt( i ) == 'B' ) count += 2; } out.println( count ); out.flush(); out.close(); }  This solution assumes that the word given as input will be one line. If it isn't, a slight modification to the input acceptance will have to be made. This runs O(N) time where N is the length of the word. answered 22 Feb '13, 07:47 2★kullalok 1.5k●11●22●36 accept rate: 14%
 0 import java.util.*; class Hello { public static void main(String args[]){ System.out.print("Enter String : "); Scanner sc=new Scanner(System.in); String input=sc.next(); int holes=0; for(int i=0;i
 0 gets.to_i.times do i=0 a=gets.chomp a.scan(/[ADOPQR]/) { i+=1 } a.scan(/B/) { i+=2 } puts i end  Ruby: 'Less Code' answered 22 Feb '13, 14:38 1 accept rate: 0%
 0 / Title: HOLES IN THE TEXT By: Chester C. Naguit / import java.util.; import java.text.; import java.io.*; class HoleInTheText{ static void sop(Object o){System.out.print(o);} static void sopln(Object o){System.out.println(o);} static void sopf(String s, Object o){System.out.printf(s,o);} static Scanner sc = new Scanner(System.in); static int[] count = new int[40]; static String str[] = new String[100]; static int t=0; public static void main(String args[]){ boolean b = true; while(b){ t = sc.nextInt(); sc.nextLine(); if(t>40){ sopln("Out of Range! 40 no. of test only!"); }else{ b = false; Count(t); } } } static void Count(int t){ boolean b = false; for(int s=0; s
 0 import java.util.*; public class Holes { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String s; int holes=0; char c[]=new char[10]; System.out.println("enter the given string to find holes"); s=sc.next(); c=s.toCharArray(); for(int i=0;i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,125

question asked: 21 Feb '13, 19:28

question was seen: 4,539 times

last updated: 06 Mar '13, 18:10