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].
11244 - Counting Stars
Moderator: Board moderators
-
- Learning poster
- Posts: 76
- Joined: Mon Jul 21, 2008 8:50 am
- Location: SUST,SYLHET,BANGLADESH.
- Contact:
Re: 11244 - Counting Stars
i didnt say the input is bad. but many many thanks mf. i now understand wht was wrong. that was a silly mistake.
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Heal The World
-
- Learning poster
- Posts: 62
- Joined: Sat Nov 21, 2009 10:17 pm
- Location: CUET,Chittagong,Bangladesh
Re: 11244 - Counting Stars
I don't what is wrong????
can you explain how to take input for this problem...........
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;
}
If you have determination, you can do anything you want....![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Re: 11244 - Counting Stars
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
Where's the problem
[code I Got it
[/code]
[code I Got it
[/code]
Re: 11244 - Counting Stars
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);
}
}
}
}
}