Page 8 of 11

Re: 11340 - Newspaper

Posted: Thu Mar 14, 2013 9:21 am
by Vot1_Bear
For those wondering, instead of using unsigned char you can simply put the char into an integer and add 188. I used this and still got AC.

Oh, and long long is enough. no need for unsigned long long.

Re: 11340 - Newspaper

Posted: Thu Mar 14, 2013 9:26 pm
by brianfry713
Munchor, try making final_value long long.

Re: 11340 - Newspaper

Posted: Tue Mar 19, 2013 10:52 pm
by paldepind
Can anybody explain how the read characters can have a negative value? I get that a standard signed char can be negative, but all standard ASCII characters are between 0 and 127 so why is it a problem?

Re: 11340 - Newspaper

Posted: Tue Mar 19, 2013 11:41 pm
by brianfry713
Don't assume that the characters in this problem have an ASCII value less than 128. Use an unsigned char.

Re: 11340 - Newspaper

Posted: Wed Mar 20, 2013 2:14 am
by Munchor
brianfry713 wrote:Munchor, try making final_value long long.
I tried and I still get WA.

But then I tried to move to unsigned char instead of char and it worked, thanks brianfry!

Re: 11340 - Newspaper

Posted: Wed Mar 20, 2013 6:39 pm
by paldepind
brianfry713 wrote:Don't assume that the characters in this problem have an ASCII value less than 128. Use an unsigned char.
So they're larger that 127 and thus the char ends up as negative is that what's going on? In that case there's odd characters in the input which is very silly.

Re: 11340 - Newspaper

Posted: Thu Jun 20, 2013 3:53 am
by hello
Got submission error....... why....?

Code: Select all

#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iterator>
using namespace std;
int main()
{
    int cases;
    scanf("%d",&cases);
    cin.get();
    while(cases--)
    {
        map<char,int>MP;

        int tot_num;
        cin>>tot_num;
        cin.get();
        while(tot_num--)
        {

            int cost;
            char ch;
            scanf("%c %d",&ch,&cost);
            cin.get();
            MP[ch]=cost;
        }
        int line,count;
        count=0;
        scanf("%d\n",&line);
        char ch;
        unsigned long long int sum=0;
        for(;;)
        {
            scanf("%c",&ch);
            sum+=MP[ch];
            if(ch=='\n')
            {
                count++;
                if(count==line)break;
            }
        }
   printf("%.2lf$\n",(double)sum/100.0);

    }
    return 0;
}

Re: 11340 - Newspaper

Posted: Thu Jun 20, 2013 10:53 pm
by brianfry713
That is AC code. Wait a while and it may change from Submission Error to AC.

Re: 11340 - Newspaper

Posted: Mon Jun 24, 2013 11:54 am
by hello
Thank you very much...................I really don't know how to thank you......... Many many thanks....

Re: 11340 - Newspaper

Posted: Fri Aug 09, 2013 3:50 pm
by raj
Need Help I have no idea why i am getting Time Limit Exceed... :( :( :(

Code: Select all

import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws IOException {
		BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader k = new BufferedReader(new FileReader("D:/uva-input.txt.txt"));
		PrintWriter z = new PrintWriter(System.out);
		int T = Integer.valueOf(k.readLine());
		while(T-->0){
			int n = Integer.valueOf(k.readLine());
			HashMap<String,Integer> h = new HashMap<String,Integer>();
			while(n-->0){
				StringTokenizer s = new StringTokenizer(k.readLine());
				String ss  = s.nextToken();
				int y = Integer.valueOf(s.nextToken());
				h.put(ss,y);
			}
			int m = Integer.valueOf(k.readLine());
			int dollar = 0;
			int cent = 0;
			while(m-->0){
				String s = k.readLine();
				for(int c = 0;c<s.length();c++){
					if(h.containsKey(s.charAt(c)+"")){
						cent = cent + h.get(s.charAt(c)+"");
						if(cent>=100){
							dollar = dollar + (int)(cent/100);
							cent = cent - 100;
						}
					}
				}
			}
			if(cent<10){
				z.println(dollar+".0"+cent+"$");
			}
			else{
				z.println(dollar+"."+cent+"$");
			}
		}
		z.flush();

	}
}

Re: 11340 - Newspaper

Posted: Sat Aug 10, 2013 12:04 am
by brianfry713
Try using BufferedWriter

11340 - Newspaper(Range of char)

Posted: Fri Aug 30, 2013 9:05 pm
by shikhorroy
In this problem Range of char is -128 to 127!!!
Why? Any explanation???

Re: 11340 - Newspaper(Range of char)

Posted: Fri Aug 30, 2013 9:45 pm
by brianfry713
Read this thread:http://acm.uva.es/board/viewtopic.php?t=24824

A signed 1 byte char always has range of -128 to 127.

For some reason the problem setter decided to use more than the standard range of 0 to 127 characters in the judge's input.

Re: 11340 - Newspaper(Range of char)

Posted: Sat Aug 31, 2013 7:54 am
by shikhorroy
Thanks...

Re: 11340 - Newspaper

Posted: Sun Nov 10, 2013 5:32 am
by rolof
Could anyone give some advice on how I could speed this up? Getting TLE. Thanks in advance!

Code: Select all

Thank you, brianfry713!