diff options
| -rw-r--r-- | 11340/newspaper.cpp | 24 | ||||
| -rw-r--r-- | 12356/buddies.c | 39 |
2 files changed, 49 insertions, 14 deletions
diff --git a/11340/newspaper.cpp b/11340/newspaper.cpp index 50f8d85..f5043cf 100644 --- a/11340/newspaper.cpp +++ b/11340/newspaper.cpp @@ -1,30 +1,26 @@ #include <iostream> #include <string> -#include <cstdio> -#include <limits> using namespace std; int main(){ int tc; cin>>tc; - for(int i=0; i<tc; i++){ - int k, costmap[256]={0}, lines, cost; + while(tc--){ + int k, costmap[500]={0}, lines, cost; double totcost=0; - unsigned char c; - string line; + string line, s; cin>>k; - for(int j=0; j<k; j++){ - scanf("%hhu", &c); - scanf("%i", &cost); - costmap[c] = cost; + while(k--){ + cin>>s>>cost; + costmap[int(s[0])+128]=cost; } - lines=cin.get(); + cin>>lines; cin.ignore(); - for(int j=0; j<lines; j++){ + while(lines--){ getline(cin, line); - for(int l=0; line[l]!='\n' && line[l]!='\r'; l++){ - totcost += costmap[line[l]]; + for(int l=0; l<line.length(); l++){ + totcost += costmap[line[l]+128]; } } cout.precision(2); diff --git a/12356/buddies.c b/12356/buddies.c new file mode 100644 index 0000000..43cabf1 --- /dev/null +++ b/12356/buddies.c @@ -0,0 +1,39 @@ +#include <stdio.h> + +int main(){ + int s, r; + scanf("%d %d", &s, &r); + while(s>0){ + int line[100000]={0}, i; + for(i=0; i<s; i++) + line[i]=1; + + int left, right; + + while(r--){ + int left_seek, right_seek; + + scanf("%d %d", &left, &right); + + for(i=left-1; i<right; i++) + line[i]=0; + + for(left_seek=left-1; line[left_seek]==0 + && left_seek>0; left_seek--); + for(right_seek=right-1; line[right_seek]==0 + && right_seek<s; right_seek++); + + if(left_seek<=0 && line[left_seek]==0) + printf("* "); + else + printf("%d ", left_seek+1); + + if(right_seek==s && line[right_seek]==0) + printf("*\n"); + else + printf("%d\n", right_seek+1); + } + printf("-\n"); + scanf("%d %d", &s, &r); + } +} |
