diff options
| author | Aditya Naik | 2018-05-10 21:20:32 -0400 |
|---|---|---|
| committer | Aditya Naik | 2018-05-10 21:20:32 -0400 |
| commit | 8a06a8c94f843e19c1e1729faede6c5f34178ba9 (patch) | |
| tree | 2eb0535713cbf0267c6f8713a33c5cc2edc5320c | |
| parent | 458fc02e1b2dd8c4434c90d0dcfdbaa5cc2e1fdb (diff) | |
stuck on newspaper
| -rw-r--r-- | 11340/newspaper.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/11340/newspaper.cpp b/11340/newspaper.cpp index 9ffa848..50f8d85 100644 --- a/11340/newspaper.cpp +++ b/11340/newspaper.cpp @@ -1,5 +1,6 @@ #include <iostream> #include <string> +#include <cstdio> #include <limits> using namespace std; @@ -9,20 +10,21 @@ int main(){ for(int i=0; i<tc; i++){ int k, costmap[256]={0}, lines, cost; double totcost=0; - char c, line[10000]; - + unsigned char c; + string line; cin>>k; for(int j=0; j<k; j++){ - cin>>c>>cost; - costmap[c+128] = cost; + scanf("%hhu", &c); + scanf("%i", &cost); + costmap[c] = cost; } - cin>>lines; + lines=cin.get(); cin.ignore(); for(int j=0; j<lines; j++){ - cin.get(line, 10000); + getline(cin, line); for(int l=0; line[l]!='\n' && line[l]!='\r'; l++){ - totcost += costmap[line[l]+128]; + totcost += costmap[line[l]]; } } cout.precision(2); |
