## 11340 - Newspaper

All about problems in Volume 113. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Vot1_Bear
New poster
Posts: 1
Joined: Mon Mar 04, 2013 12:57 pm

### Re: 11340 - Newspaper

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.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11340 - Newspaper

Munchor, try making final_value long long.
Check input and AC output for thousands of problems on uDebug!
paldepind
New poster
Posts: 2
Joined: Tue Mar 19, 2013 10:46 pm

### Re: 11340 - Newspaper

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?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11340 - Newspaper

Don't assume that the characters in this problem have an ASCII value less than 128. Use an unsigned char.
Check input and AC output for thousands of problems on uDebug!
Munchor
New poster
Posts: 19
Joined: Sun Mar 03, 2013 4:03 pm

### Re: 11340 - Newspaper

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!
paldepind
New poster
Posts: 2
Joined: Tue Mar 19, 2013 10:46 pm

### Re: 11340 - Newspaper

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.
hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

### Re: 11340 - Newspaper

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;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11340 - Newspaper

That is AC code. Wait a while and it may change from Submission Error to AC.
Check input and AC output for thousands of problems on uDebug!
hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

### Re: 11340 - Newspaper

Thank you very much...................I really don't know how to thank you......... Many many thanks....
raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

### Re: 11340 - Newspaper

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();

}
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11340 - Newspaper

Try using BufferedWriter
Check input and AC output for thousands of problems on uDebug!
shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

### 11340 - Newspaper(Range of char)

In this problem Range of char is -128 to 127!!!
Why? Any explanation???
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11340 - Newspaper(Range of char)

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.
Check input and AC output for thousands of problems on uDebug!
shikhorroy
New poster
Posts: 27
Joined: Sat Jul 27, 2013 3:52 am

### Re: 11340 - Newspaper(Range of char)

Thanks...
rolof
New poster
Posts: 1
Joined: Sun Nov 10, 2013 5:28 am

### Re: 11340 - Newspaper

Could anyone give some advice on how I could speed this up? Getting TLE. Thanks in advance!

Code: Select all

Thank you, brianfry713!
Last edited by rolof on Wed Nov 13, 2013 12:14 am, edited 1 time in total.