Page 9 of 12

Re: Hashmat Warrior

Posted: Thu Jul 01, 2010 10:54 pm
by rahid
This problem wants the output must be in positive. For the input 100 200 it should be output 100. But what about the input 200 100? Your code should give the output -100. But it should be 100. So make it possible.

Thats it!!

:D :) :D

Re: 10055 - Hashmat the Brave Warrior

Posted: Thu Sep 23, 2010 1:54 pm
by anik.bit0104
You should have used a loop. Your code would be terminated after one computation.

Re: 10055 - Hashmat the Brave Warrior

Posted: Thu Sep 23, 2010 3:17 pm
by anik.bit0104
I'm having runtime error in my java code of this program after submitting. But in my eclipse ide, it works fine.
Can you guys tell me what's the problem?

class Vol0Prob10055Hashmat {

public static void main(String[] args) {
java.util.Scanner sc=new java.util.Scanner(System.in);


while(sc.hasNextLong()){

System.out.println(java.lang.Math.abs(sc.nextLong()-sc.nextLong()));
}
}
}

Re: cannot the understand the mistake

Posted: Fri Nov 05, 2010 12:44 am
by raine_iut
asif_khan_ak_07 wrote:which data type should i use?

long long

Re: cannot the understand the mistake

Posted: Fri Nov 05, 2010 2:55 am
by mf
No, it ain't.

Re: cannot the understand the mistake

Posted: Fri Nov 05, 2010 12:23 pm
by raine_iut
mf wrote:No, it ain't.

the minimal range of ''unsigned long int'' is 1 less than the highest possible input of this problem, is this the reason?

Re: cannot the understand the mistake

Posted: Fri Nov 05, 2010 6:28 pm
by mf
Yes.

On a 32-bit OS (which UVa judge uses), "unsigned long int" is an unsigned 32-bit integer, and so it can't represent 2^32, which is a possible input in this problem.

Re: 10055 - Hashmat the Brave Warrior

Posted: Sat Nov 20, 2010 2:37 pm
by mashaheer
hi all.
i got AC from both below codes.now my question is:
in all problem this 2 way of inputing and outputing are correct?or each one has special situation?
in this code:
get each input and print the output: ----------------------
first get all inputs and after eof print outputs:

Re: 10055 - Hashmat the Brave Warrior

Posted: Sun Nov 21, 2010 1:57 am
by mf
Yes, you may read all the input before printing the output, if you'd like.
But it's more usual to just read and solve the test cases one-by-one.

Re: 10055 - Hashmat the Brave Warrior

Posted: Sun Nov 21, 2010 10:18 pm
by mashaheer
thanks dear mf!

Re: 10055 - Hashmat the Brave Warrior

Posted: Wed Mar 02, 2011 1:20 pm
by shahidul
#include <iostream>
#include<stdio.h>
using namespace std;

int main()
{
unsigned int a,b;
while(scanf("%u %u",&a,&b)!=EOF){
if(a>b)printf("%u\n",(a-b));
else printf("%u\n",(b-a));
}
return 0;
}

Please enlighten me!

Posted: Sat Sep 17, 2011 4:23 pm
by moxlotus
This is my first time attempting a problem on UVa. Therefore I have decided to pick something really easy, so that I will be able to figure out how does the online judge works.
The problem is 10055 - Hashmat the Brave Warrior. A really straightforward problem for the novice. As I used VS2008 to compile the codes, there are some compilation errors that i have received when i submitted it online.(no compilation error with my VS2008) Fortunately, I was able to solve the compilation errors by searching it online.

Now the issue is that I have got a Wrong Answer as my verdict which i don't see anything wrong with my solution.

Can someone out there please enlighten me? is my handling of input and output correct?
The question says Input:standard input, Output: standard ouput. Does that means i m only need to use cout/cin?

Code: Select all

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>

using namespace std;

vector<string> INPUTS;
vector<int> OUTPUTS;
void core()
{

	int loop = INPUTS.size();
	for(int i = 0; i < loop; i++)
	{

		int first = 0, second = 0;
		string temp = INPUTS[i];
		int count = temp.size();
		first = atoi(&temp[0]);
		for(int j = 0; j < count; j++)
		{
			if(isspace(temp[j]))
			{
				second = atoi(&temp[j + 1]);
				break;
			}
		}
		OUTPUTS.push_back(second - first);
	}
}
int main(int argc, char *argv[])
{
	ifstream the_file ("Input.txt");
	if (!the_file.is_open())
	{
		cout<<"Could not open file\n";
		//system("pause");
		return 0;
	}
	else {
		string x;
		while ( !the_file.eof())
		{
			getline(the_file, x);
			INPUTS.push_back(x);
		}

		the_file.close();
	}

	core();
	ofstream file("output.txt");
	if(!file.is_open())
	{
		cout<<"Fail to create dump file"<<endl;
		//system("pause");
		return 0;
	}
	else
	{
		//output to the output file
		for(int a = 0; a <OUTPUTS.size(); a++ )
		{
			file<<OUTPUTS[a]<<endl;
		}
	}
	file.close();
	return 0;
}


Re: Please enlighten me!

Posted: Tue Oct 11, 2011 10:43 am
by spalac24
The input is made from stdin, you'll need to use cin, scanf() or other functions that help you with that.

10055 Getting TLE

Posted: Wed Nov 30, 2011 4:25 pm
by sum_sim
Can anyone tell me what is wrong with the code? I've tried several times but I'm getting TLE. Please help.

Code: Select all

import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String args[]){
		long a, b, c;
		Scanner cin = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		while(cin.hasNextLong()){
			a = cin.nextLong();
			b = cin.nextLong();
			
			c = a-b;
			
			if(c<0) c *=-1;
			
			System.out.println(c);
		}
	}
}

10055 Getting TLE

Posted: Wed Nov 30, 2011 4:28 pm
by sum_sim
Can anyone tell me what is wrong with the code? I've tried several time but getting TLE.
  • hasNext();
  • hasNextLong()
none of them are working. Please help.

Code: Select all

import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String args[]){
		long a, b, c;
		Scanner cin = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		while(cin.hasNextLong()){
			a = cin.nextLong();
			b = cin.nextLong();
			
			c = a-b;
			
			if(c<0) c *=-1;
			
			System.out.println(c);
		}
	}
}