11340 - Newspaper
Moderator: Board moderators
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.
Oh, and long long is enough. no need for unsigned long long.
-
- 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!
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?
-
- 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!
Re: 11340 - Newspaper
I tried and I still get WA.brianfry713 wrote:Munchor, try making final_value long long.
But then I tried to move to unsigned char instead of char and it worked, thanks brianfry!
Re: 11340 - Newspaper
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.brianfry713 wrote:Don't assume that the characters in this problem have an ASCII value less than 128. Use an unsigned char.
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;
}
-
- 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!
Re: 11340 - Newspaper
Thank you very much...................I really don't know how to thank you......... Many many thanks....
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();
}
}
-
- 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!
-
- 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???
Why? Any explanation???
-
- 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.
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!
-
- New poster
- Posts: 27
- Joined: Sat Jul 27, 2013 3:52 am
Re: 11340 - Newspaper(Range of char)
Thanks...
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.