11244 - Counting Stars

All about problems in Volume 112. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: 11244 - Counting Stars

Post by mf » Fri Jul 31, 2009 2:30 pm

Well, if you program stops crashing when you increase array sizes, it doesn't necessarily mean the input is bad. Almost always the bug will be in your own code.

Here, it seems to me that "int array[13305]" is too small, because if input consisted of 100x100 asterisks, your program willl attempt to overwrite array[0], array[1], ..., array[19999].

calicratis19
Learning poster
Posts: 76
Joined: Mon Jul 21, 2008 8:50 am
Location: SUST,SYLHET,BANGLADESH.
Contact:

Re: 11244 - Counting Stars

Post by calicratis19 » Fri Jul 31, 2009 6:09 pm

i didnt say the input is bad. but many many thanks mf. i now understand wht was wrong. that was a silly mistake. :) :)
Heal The World

naseef_07cuet
Learning poster
Posts: 62
Joined: Sat Nov 21, 2009 10:17 pm
Location: CUET,Chittagong,Bangladesh

Re: 11244 - Counting Stars

Post by naseef_07cuet » Wed May 11, 2011 4:40 pm

I don't what is wrong????

Code: Select all

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    char a[104][104],ss;
    long c,r,s,i,j,k;
    while(scanf("%ld%ld",&r,&c)==2)
    {
    getchar();
    if(r==0 && c==0)
    break;
    k=0,j=0;
    for(i=0;i<r;i++)
    {
                    gets(a[i]);
                    getchar();
    }
    s=0;
    for(i=0;i<r;i++)
    for(j=0;j<c;j++)
    {
                    if(a[i][j]=='*')
                    {
                                    if(i==0)
                                    {
                                            if(j==0)
                                            {
                                                    if(a[i][j+1]=='*' || a[i+1][j]=='*' || a[i+1][j+1]=='*')
                                                    continue;
                                                    else s++;
                                            }
                                            else if(j==c-1)
                                            {
                                                 if(a[i][j-1]=='*' || a[i+1][j]=='*' || a[i-1][j-1]=='*')
                                                 continue ;
                                                 else s++;     
                                            }
                                            else
                                            {
                                                if(a[i][j+1]=='*' || a[i][j-1]=='*' || a[i+1][j]=='*' || a[i+1][j+1] =='*' || a[i+1][j-1]=='*')
                                                continue;
                                                else s++;
                                            }
                                    }
                                    else if(i==r-1)
                                    {
                                         if(j==0)
                                         {
                                                 if(a[i-1][j]=='*' || a[i-1][j+1]=='*' || a[i][j+1]=='*')
                                                 continue;
                                                 else s++;
                                         }
                                         else if(j==c-1)
                                         {
                                                   if(a[i-1][j]=='*' || a[i-1][j-1]=='*' || a[i][j-1]=='*')
                                                   continue;
                                                   else s++;
                                         }
                                         else
                                         {
                                             if(a[i][j-1]=='*' || a[i][j+1]=='*' || a[i-1][j-1]=='*' || a[i-1][j]=='*' || a[i-1][j+1]=='*')
                                             continue;
                                             else s++;
                                         }
                                    }
                                    else
                                    {        if(a[i][j-1]=='*' || a[i][j+1]=='*' || a[i-1][j]=='*' || a[i+1][j]=='*' || a[i-1][j-1]=='*' || a[i-1][j+1]=='*'|| a[i+1][j-1]=='*' || a[i+1][j+1]=='*')
                                             continue;
                                             else s++;
                                    }        
                                     
                    }
    }
    cout<<s<<endl;
    }
    return 0;
}
can you explain how to take input for this problem...........
If you have determination, you can do anything you want....:)

buppy
New poster
Posts: 2
Joined: Tue Nov 08, 2011 11:26 pm

Re: 11244 - Counting Stars

Post by buppy » Tue Nov 08, 2011 11:41 pm

help,i am getting wa

Code: Select all

#include<stdio.h>
#include<string.h>
char a[105][105],c;
int size,hv,m,n,f;

int main()
{
	 int i,j,f;
	 while(scanf("%d%d",&m,&n)==2&&(m+n))
	 {
         scanf("%c",&c);
	 f=0;
		  for(i=0;i<m;i++)
				gets(a[i]);
		  for(i=0;i<m;i++){
		  for(j=0;j<m;j++){
		  if(a[i][j]=='*'&&i>0&&i!=m-1){
		  if(a[i][j-1]=='*'||a[i][j+1]=='*'||a[i-1][j-1]=='*'||a[i-1][j+1]=='*'||a[i-1][j]=='*'||a[i+1][j-1]=='*'||a[i+1][j+1]=='*'||a[i+1][j]=='*')
		  f=f;
		  else
		  f++;
		  }
		  else if(a[i][j]=='*'&&i==0){
		  if(a[i][j-1]=='*'||a[i][j+1]=='*'||a[i+1][j-1]=='*'||a[i+1][j]=='*'||a[i+1][j+1]=='*')
		  f=f;
		  else
		  f++;
		  }
		  else if(a[i][j]=='*'&&i==m-1){
		  if(a[i][j-1]=='*'||a[i][j+1]=='*'||a[i-1][j-1]=='*'||a[i-1][j]=='*'||a[i-1][j+1]=='*')
		  f=f;
		  else
		  f++;
		  }
		  }
		  }
printf("%d\n",f);
	 }
	 return 0;
}

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 11244 - Counting Stars

Post by hello » Fri Oct 18, 2013 10:12 pm

Where's the problem

[code I Got it
[/code]

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11244 - Counting Stars

Post by uDebug » Tue Apr 07, 2015 8:10 am

Added some input I found useful during testing / debugging here:

http://www.udebug.com/UVa/11244
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

emrankdr
New poster
Posts: 2
Joined: Mon Dec 22, 2014 9:40 am

Re: 11244 - Counting Stars

Post by emrankdr » Mon Jun 29, 2015 7:30 am

Why my code is showing runtime error? Please help

Code: Select all


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author emran.kdr
 */
 class Main{

    static char A[][] = new char[1001][1001];
    static Scanner sc = new Scanner(System.in);
    static int m;
    static int n;
    static int count = 0;

    /**
     * @param args the command line arguments
     */
     static void fill(int x, int y) {
        A[x][y] = '&';
        if (y - 1 >= 0 && A[x][y - 1] == '*') {
            
            count = 0;
            fill(x, y - 1);
            
        }//left
        if (y + 1 < n && A[x][y + 1] == '*') {
           count = 0;
            fill(x, y + 1);
            
        }
        if (x - 1 >= 0 && A[x - 1][y] == '*') {
           count = 0;
            fill(x - 1, y);
            
        }
        if (x + 1 < m && A[x + 1][y] == '*') {
            count = 0;
            fill(x + 1, y);
            
        }
        if (x - 1 >= 0 && y - 1 >= 0 && A[x - 1][y - 1] == '*') {
             count = 0;
            fill(x - 1, y - 1);
           
        }
        if (x - 1 >= 0 && y + 1 < n && A[x - 1][y + 1] == '*') {
             count = 0;
            fill(x - 1, y + 1);
           
        }
        if (x + 1 < m && y - 1 >= 0 && A[x + 1][y - 1] == '*') {
             count = 0;
            fill(x + 1, y - 1);
           
        }
        if (x + 1 < m && y + 1 < n && A[x + 1][y + 1] == '*') {
           count = 0;
            fill(x + 1, y + 1);
            
        }
    }

    public static void main(String[] args)  {
        // TODO code application logic here

        while (sc.hasNext()) {
            m = sc.nextInt();
            n = sc.nextInt();
            if (m == 0 && n == 0) {
                break;
            }

            readcase();
            slovecase();

            System.out.println(count);
        }
    }

    static void readcase()  {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for (int k = 0; k < m; k++) {

            try {
                A[k] = br.readLine().toCharArray();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    }

     static void slovecase() {
        int i, j;
        for (i = 0; i < m; i++) {
            for (j = 0; j < n; j++) {
                if (A[i][j] == '*') {
                    count++;
                    fill(i, j);
                }
            }
        }

    }

}

Post Reply

Return to “Volume 112 (11200-11299)”