414 - Machined Surfaces
Moderator: Board moderators
414
I get the correct result for the 1st case.
then I get wrong answer.
Here is my code.........
#include <stdio.h>
void main()
{
int x,y,a,b,c,d,n,h,t,xn[13];
char im[13][26];
do
{
scanf("%d",&n);
for(a=0;a<n;a++)
for(b=0;b<25;b++)
scanf("%c",&im[a]);
for(a=0;a<n;a++)
{
c=0;
for(b=0;b<25;b++)
{
if(im[a]!='X')
continue;
c++;
}
xn[a]=c;
}
h=0;
for(a=0;a<n;a++)
if(xn[a]>h)
h=xn[a];
t=0;
for(a=0;a<n;a++)
t+=h-xn[a];
printf("%d\n",t);
}while(n!=0);
}
[/code]
then I get wrong answer.
Here is my code.........
#include <stdio.h>
void main()
{
int x,y,a,b,c,d,n,h,t,xn[13];
char im[13][26];
do
{
scanf("%d",&n);
for(a=0;a<n;a++)
for(b=0;b<25;b++)
scanf("%c",&im[a]);
for(a=0;a<n;a++)
{
c=0;
for(b=0;b<25;b++)
{
if(im[a]!='X')
continue;
c++;
}
xn[a]=c;
}
h=0;
for(a=0;a<n;a++)
if(xn[a]>h)
h=xn[a];
t=0;
for(a=0;a<n;a++)
t+=h-xn[a];
printf("%d\n",t);
}while(n!=0);
}
[/code]
Razib
Please, give me more sample input&output 414
[c]
can you give more sample input and output, for 414 problem?
and could you tell me the input 'x' or 'X'.
thanks for your help..........[/c]
can you give more sample input and output, for 414 problem?
and could you tell me the input 'x' or 'X'.
thanks for your help..........[/c]
1
XBBBBBBBBBBBBBBBBBBBBBBBX
3
XBBBBBBBBBBBBBBBBBBBBBBBX
XXXXXXXXXXXXBBXXXXXXXXXXX
XBBBBBBBBBBBBBBBBBBBBBBBX
1
XXXXXXXXXXXXXXXXXXXXXXXXX
3
XXXBBBBBBBBBBBBBBBBBBBBBX
XXXXXXXBBBBBBBBBBBBBBXXXX
XXXXXXXXBBBBBBBBBBBBBBBBX
{"B" shows the space.}
Output:
0
42
0
9
The input is 'X' (UPPERCASE LETTER)
Good luck!
Regards,
Angga888
XBBBBBBBBBBBBBBBBBBBBBBBX
3
XBBBBBBBBBBBBBBBBBBBBBBBX
XXXXXXXXXXXXBBXXXXXXXXXXX
XBBBBBBBBBBBBBBBBBBBBBBBX
1
XXXXXXXXXXXXXXXXXXXXXXXXX
3
XXXBBBBBBBBBBBBBBBBBBBBBX
XXXXXXXBBBBBBBBBBBBBBXXXX
XXXXXXXXBBBBBBBBBBBBBBBBX
{"B" shows the space.}
Output:
0
42
0
9
The input is 'X' (UPPERCASE LETTER)
Good luck!

Regards,
Angga888
Can you tell me what's wrong with my code. I verified with all this input and it works... The idea is that I calculate the sum of all spaces (sum) and the minimum number of the spaces in a line (min). The oputput is then sum-n*min... Is it ok???
[pascal]
program p414;
var s:string;
sum:longint;
n,min,i,k,j:integer;
begin
while not eof(input) do
begin
readln(n);
min:=MaxInt; sum:=0;
for i:=1 to n do
begin
readln(s);
while s[1]=' ' do delete(s,1,1);
j:=length(s);
while s[j]=' ' do
begin
delete(s,j,1);
j:=j-1;
end;
k:=0;
j:=pos(' ',s);
while j>0 do
begin
delete(s,j,1);
k:=k+1;
j:=pos(' ',s);
end;
sum:=sum+k;
if min>k then
min:=k;
end;
writeln(sum-min*n);
end;
end.
[/pascal]
Thanx
[pascal]
program p414;
var s:string;
sum:longint;
n,min,i,k,j:integer;
begin
while not eof(input) do
begin
readln(n);
min:=MaxInt; sum:=0;
for i:=1 to n do
begin
readln(s);
while s[1]=' ' do delete(s,1,1);
j:=length(s);
while s[j]=' ' do
begin
delete(s,j,1);
j:=j-1;
end;
k:=0;
j:=pos(' ',s);
while j>0 do
begin
delete(s,j,1);
k:=k+1;
j:=pos(' ',s);
end;
sum:=sum+k;
if min>k then
min:=k;
end;
writeln(sum-min*n);
end;
end.
[/pascal]
Thanx
414-Is anything wrong with my code? The answers are correct
All the answers seem to be correct. I don't know why I get WA.....
Can anyone help me out?
Thanks in advance,
joao sarmento
[java]
import java.io.*;
class Main{
public static void main (String args[]){
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}
void Begin(){
int [] blanks = new int[13];
int x = -1;
int result = 0;
int line = -1;
int lines = 0;
while(x != 0){
try{
x = System.in.read();
}
catch (IOException e){
System.out.println(e.getMessage());
System.out.println("Fatal error. Ending Program.");
System.exit(0);
}
if (x == '0'){
x = 0;
}
else if (x > '0' && x <= '9'){
lines = x - '0';
line = -1;
}
else if (x == 'X' || x == '\r'){
}
else if (x == ' ')
blanks[line]++;
else if (x == '\n'){
line++;
if (line >= lines){
int min = 25;
for(int i = 0; i < lines; i++)
if (blanks < min)
min = blanks;
for(int i = 0; i < lines; i++)
result+= (blanks - min);
System.out.println(result);
blanks = new int [13];
result = 0;
lines = 0;
line = -1;
}
}
}
}
}[/java]
Can anyone help me out?
Thanks in advance,
joao sarmento
[java]
import java.io.*;
class Main{
public static void main (String args[]){
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}
void Begin(){
int [] blanks = new int[13];
int x = -1;
int result = 0;
int line = -1;
int lines = 0;
while(x != 0){
try{
x = System.in.read();
}
catch (IOException e){
System.out.println(e.getMessage());
System.out.println("Fatal error. Ending Program.");
System.exit(0);
}
if (x == '0'){
x = 0;
}
else if (x > '0' && x <= '9'){
lines = x - '0';
line = -1;
}
else if (x == 'X' || x == '\r'){
}
else if (x == ' ')
blanks[line]++;
else if (x == '\n'){
line++;
if (line >= lines){
int min = 25;
for(int i = 0; i < lines; i++)
if (blanks < min)
min = blanks;
for(int i = 0; i < lines; i++)
result+= (blanks - min);
System.out.println(result);
blanks = new int [13];
result = 0;
lines = 0;
line = -1;
}
}
}
}
}[/java]
-----------------
Jo
Jo
414-Wa? Why? Please help!
I've got a problem with my program.
Please help me
These is source
Or give a dificolt input
Help me!!!!!!
Please help me
These is source
Code: Select all
var
c,il,suma,a,b,min:longint;
wyn:array[1..13]of longint;
s:string;
czy:boolean;
begin
{assign(input,'414.in');
reset(input);}
readln(il);
while il<>0 do
begin
min:=maxlongint;
czy:=false;
for a:=1 to il do
begin
readln(s);
c:=0;
b:=1;
while s[b]<>'X' do
begin
inc(b);
if b=26 then break;
end;
if (b<25)and(length(s)>0) then
begin
while s[b]='X' do
begin
inc(b);
if b=25 then
begin
min:=0;
czy:=true;
break;
end;
end;
if b<25 then
while s[b]<>'X' do
begin
inc(b);
inc(c);
if b=26 then
begin
min:=0;
czy:=true;
break;
end;
end;
if min>c then min:=c;
wyn[a]:=c;
end
end;
suma:=0;
for b:=1 to il do
if wyn[b]>0 then
suma:=suma+wyn[b]-min;
if not czy then writeln(suma) else writeln('0');
readln(il);
end;
end.
Help me!!!!!!
414 - Machined Surfaces
this is my source code.......
program void;
{uses wincrt;}
var table:array[1..12,1..25]of char;
n,i,j,total,min,row,result:integer;
begin
readln(n);
while n<>0 do
begin
min:=26;
result:=0;
for i:=1 to n do
begin
for j:=1 to 25 do
read(table[i,j]);
readln
end;
for i:=1 to n do
begin
total:=0;
for j:=1 to 25 do
if table[i,j]='B'
then total:=total+1;
if total<min
then begin
min:=total;
row:=i
end
end;
for i:=1 to n do
if i<>row then
begin
total:=0;
for j:=1 to 25 do
if table[i,j]='B'
then total:=total+1;
result:=result+total-min
end;
writeln(result);
readln(n)
end
end.
program void;
{uses wincrt;}
var table:array[1..12,1..25]of char;
n,i,j,total,min,row,result:integer;
begin
readln(n);
while n<>0 do
begin
min:=26;
result:=0;
for i:=1 to n do
begin
for j:=1 to 25 do
read(table[i,j]);
readln
end;
for i:=1 to n do
begin
total:=0;
for j:=1 to 25 do
if table[i,j]='B'
then total:=total+1;
if total<min
then begin
min:=total;
row:=i
end
end;
for i:=1 to n do
if i<>row then
begin
total:=0;
for j:=1 to 25 do
if table[i,j]='B'
then total:=total+1;
result:=result+total-min
end;
writeln(result);
readln(n)
end
end.
-
- New poster
- Posts: 36
- Joined: Mon Jun 19, 2006 5:43 pm
- Location: Bangladesh
- Contact:
414 WA, need help!
Hi!
i got WA in 414.
i think, the problem is not clear 2 me.
can anyboby describe me d problem.
Here is my code also.
Any suggestion plz........
i got WA in 414.

i think, the problem is not clear 2 me.
can anyboby describe me d problem.
i dont understant d above line of the problem descrip tion.There will never be more than a single blank region in any row.
Here is my code also.
Code: Select all
Last edited by deena sultana on Thu Jun 22, 2006 8:58 pm, edited 1 time in total.
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
Miss dena,

what you have done when N=1:(!!!!!!!!!!!

what you have done when N=1:(!!!!!!!!!!!
Code: Select all
.....
if(num==0)
break;
else if(num==1)
cout<<0<<endl; [b]"dont take Input yet before print OUPUT "[/b]
else
{
int count=0;
loop=num;
while(loop--)
{
gets(str); [b]" you done it heer" ...:)[/b]
....