- 1
- 2
include<stdio.h>
int abs(int x) { if(x<0) return -x; return x; }
int main() { int cokpos,fpos,spos; char x; while(1) { scanf("%d",&cokpos);
if(cok_pos==5280)
{
return 0;
}
f_pos=0;
while(1)
{
scanf("%d",&s_pos);
if(s_pos==cok_pos)
{
printf("Moving from %d to %d: found it!\n",f_pos,s_pos);
break;
}
if(abs(f_pos-cok_pos)>abs(s_pos-cok_pos))
printf("Moving from %d to %d: warmer.\n",f_pos,s_pos);
else if(abs(f_pos-cok_pos)<abs(s_pos-cok_pos))
printf("Moving from %d to %d: colder.\n",f_pos,s_pos);
else
printf("Moving from %d to %d: same.\n",f_pos,s_pos);
f_pos=s_pos;
}
printf("\n");
}
return 0;
} can u check wats problem in it?
ankurkumar said:
can u please check my code?
every time i submit it shows persentation error!!!
In the Output clearly mentioned that:
Have a blank line between the output for different input lines.
By between means after the last output block, you should not output any addition \n
.
You can check my code for this problem:
int main() {
int f, k, p, a, b, c=0;
while(~scanf("%d",&f) && f-5280) {
printf(c++?"\n":"");
p = 0;
while(~scanf("%d", &k)) {
printf("Moving from %d to %d: ",p,k);
a = p > f ? p - f: f - p;
b = k > f ? k - f: f - k;
if (!b && printf("found it!\n")) break;
if (a==b) printf("same.\n");
if (a>b) printf("warmer.\n");
if (a<b) printf("colder.\n");
p = k;
}
}
return 0;
}
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
int cookie= sc.nextInt();
int ant = 0 , sig;
int dist_a,dist_b;
if (cookie >= 5280) break;
while(true){
sig= sc.nextInt();
System.out.print("Moving from " + ant + " to " + sig + ":");
dist_a = Math.abs(cookie - ant);
dist_b = Math.abs(cookie - sig);
if(dist_b == 0 ){
System.out.print(" found it!");
System.out.println();
break;
}
if(dist_a == dist_b) System.out.print(" same.");
if(dist_a > dist_b) System.out.print(" warmer.");
if(dist_a < dist_b) System.out.print(" colder.");
System.out.println();
ant = sig;
}
}
}
} presentation error? why T.T
Have a look on my previous reply!
You have to print a newline
between the output for each test, not after each one!
Hi there,
This is my code, i submitted it many times, but it continue to say representation error, thanks for any help,
import java.util.Scanner;
public class Main { public static void main(String[] args) { Integer place; Integer lastnum; Integer currentnum;//define variables //Integer counter=0;
Scanner in = new Scanner(System.in);
place = in.nextInt();
while (place!=5280)
{
Integer flag = 0;
Integer reptime = 0;
currentnum = 0;
lastnum = 0;
while((flag==0)&&(reptime!=21))
{
currentnum = in.nextInt();
reptime++;
if(currentnum==place)
{
System.out.print("Moving from "+lastnum+" to "+currentnum+": found it!\n");
System.out.print("\n");
flag = 1;
}
else
{
if(Math.abs(currentnum-place) == Math.abs(lastnum-place))
{
System.out.print("Moving from "+lastnum+" to "+currentnum+": same.\n");
lastnum = currentnum;
}
if(Math.abs(currentnum-place) > Math.abs(lastnum-place))
{
System.out.print("Moving from "+lastnum+" to "+currentnum+": colder.\n");
lastnum = currentnum;
}
if(Math.abs(currentnum-place) < Math.abs(lastnum-place))
{
System.out.print("Moving from "+lastnum+" to "+currentnum+": warmer.\n");
lastnum = currentnum;
}
}
}
place = in.nextInt();
}
}
}
Read the previous reply :)
Yeh, It works now ;)
even after I skip a blank line between test cases it says always presentation error!
IromY said:
even after I skip a blank line between test cases it says always presentation error!
You have to print a blank line between the output cases.
You should not print any excess newlines after the last output case. Pay attention to the word "Between".
In order to post something you must login first. You can use the form in the top of this page.