Code: Select all
removed
Moderator: Board moderators
Code: Select all
removed
and then i got ac.printf("%ld.%02ld$\n",dollar,cents);
Code: Select all
#include <stdio.h>
#include <string.h>
[b]#define to_unsigned_char(x) if (x < 0) x += 256[/b]
int table[1000000];
int main()
{
char article[1000000];
int n;
int k;
[b] char c;[/b]
int p;
int m;
int len;
long long sum_dollar;
int sum_cents;
int i;
int j;
int t;
scanf(" %d",&n);
int first = 1;
while (n-- > 0)
{
scanf(" %d",&k);
for (j = 0;j < 512;j++)
{
table[j] = 0;
}
while (k-- > 0)
{
[b] scanf(" %c %d",&c, &p);
t = c;
to_unsigned_char(t);
table[(int)t] = p;[/b]
}
scanf("%d",&m);
sum_dollar = 0;
sum_cents = 0;
while (m-- > 0)
{
scanf(" %[^\n]",article);
for (k = 0;article[k];k++)
{
[b]t = article[k];
to_unsigned_char(t);
sum_cents += table[t];
if (sum_cents >= 100) {
sum_cents -= 100;
sum_dollar++;
}[/b]
}
}
[b]printf("%lld", sum_dollar);
if (sum_cents > 0)
{
printf(".%2d$\n", sum_cents);
}
else
{
printf(".0$\n");
}[/b]
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
#define to_unsigned_char(x) if (x < 0) x += 256
int table[1000000];
int main()
{
char article[1000000];
...
unsigned char c;
...
long long sum_dollar;
int sum_cents;
...
while (k-- > 0)
{
c = cin.get(); //to skip whitespaces
c = cin.get(); // get the char
t = c; // convert it to int
to_unsigned_char(t);
cin >> p;
table[(int)t] = p;
}
...
while (m-- > 0)
{
scanf(" %[^\n]",article);
for (k = 0;article[k];k++)
{
t = article[k];
to_unsigned_char(t);
sum_cents += table[t];
if (sum_cents >= 100) {
sum_cents -= 100;
sum_dollar++;
}
}
}
...
printf("%lld.%02d$\n", sum_dollar, sum_cents);[/u]
Code: Select all
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
#define to_unsigned_char(x) if (x < 0) x += 256
int table[1000000];
int main()
{
unsigned char article[1000000];
int n;
int k;
unsigned char c;
int p;
int m;
int len;
long long sum_dollar;
int sum_cents;
int i;
int j;
int t;
scanf(" %d",&n);
int first = 1;
while (n-- > 0)
{
scanf(" %d",&k);
for (j = 0;j < 512;j++)
{
table[j] = 0;
}
[b]while (k-- > 0)
{
c = cin.get();
c = cin.get();
t = c;
// to_unsigned_char(t);
cin >> p;
table[(int)t] = p;
}[/b]
scanf("%d",&m);
sum_dollar = 0;
sum_cents = 0;
c = cin.get();
while (m-- > 0)
{
[b]while ((c = cin.get()) != '\n')
{
t = c;
// printf("c: %c\n", c);
// to_unsigned_char(t);
sum_cents += table[t];
if (sum_cents >= 100) {
sum_cents -= 100;
sum_dollar++;
}
}[/b]
}
printf("%lld.%02d$\n", sum_dollar, sum_cents);
// if (sum_cents > 0)
// {
// printf(".%02d$\n", sum_cents);
// }
// else
// {
// printf(".0$\n");
// }
}
return 0;
}