Page 2 of 2
Re: 11244 - Counting Stars
Posted: Fri Jul 31, 2009 2:30 pm
by mf
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].
Re: 11244 - Counting Stars
Posted: Fri Jul 31, 2009 6:09 pm
by calicratis19
i didnt say the input is bad. but many many thanks mf. i now understand wht was wrong. that was a silly mistake.

Re: 11244 - Counting Stars
Posted: Wed May 11, 2011 4:40 pm
by naseef_07cuet
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...........
Re: 11244 - Counting Stars
Posted: Tue Nov 08, 2011 11:41 pm
by buppy
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;
}
Re: 11244 - Counting Stars
Posted: Fri Oct 18, 2013 10:12 pm
by hello
Where's the problem
[code I Got it
[/code]
Re: 11244 - Counting Stars
Posted: Tue Apr 07, 2015 8:10 am
by uDebug
Added some input I found useful during testing / debugging here:
http://www.udebug.com/UVa/11244
Re: 11244 - Counting Stars
Posted: Mon Jun 29, 2015 7:30 am
by emrankdr
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);
}
}
}
}
}