The UVa forum to the rescue again... ACCEPTED !!!
____________________________________________________________________
Question: Newspaper
____________________________________________________________________
#include "iostream.h"
#include "iomanip.h"
int main()
{
int n;
cin >> n;
for(int t = 0; t < n; t++) {
unsigned long long int arr[256];
for(int i = 0; i < 256; i++) arr[i] = 0;
int k;
cin >> k;
for(int j = 0; j < k; j++) {
cin.ignore();
unsigned char key = cin.get();
long long int value;
cin >> value;
arr[int(key)] = value;
}
int m;
unsigned long long int pay = 0;
cin >> m;
cin.ignore();
for(int i = 0; i < m; i++) {
unsigned char c = cin.get();
while(c != '\n') {
pay += arr[int(c)];
c = cin.get();
}
}
cout.setf(ios::fixed);
cout << setprecision(2) << pay / 100 << "." << setw(2) << setfill('0') << pay % 100 <<"$" << endl;
}
return 0;
}____________________________________________________________________
Sunday, December 9, 2007
Newspaper
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment