CF Find the problem

来源:互联网 发布:在线影视自动采集源码 编辑:程序博客网 时间:2024/06/02 22:41
F. Find The Problem!
Sohrab & Sepehr are problem-setters of Kashan
programming contest. After they prepared their problems, the
sponsor of event gives them two new raw problems. He asks
them to add the two new problems to the problem set. Now you
should solve one of those problems. Sohrab & Sepehr doesn’t
have any time to prepare the problem, so they explain the original
one given by sponsor and you have to discover what it actually
asks, then solve it!
In this problem you are given a mysterious table and you should change it to a strange one! See
the example to find out how to do it.
Input (Standard Input)
The first line of input contains an integer indicating the number of test cases.
Fig1. A nostalgic figure from IOI95
Machine Part Code
R1 P1 C1
R1 P2 C2
R1 P3 C3
R1 P4 C4
R2 P1 C5
R2 P5 C6
R2 P6 C7
R2 P7 C8
R3 P5 C9
Fig1. Mysterious table
P1 P2 P3 P4 P5 P6 P7
R1 C1 C2 C3 C4
R2 C5 C6 C7 C8
R3 C9
Fig2. Strange table
Page 10 of 21
First line of each test case contains an integer number which is the number of
data rows in the mysterious table. In each of next lines there are three space-separated
words representing saved data fields in the row of mysterious table.
All data in the table only consists of uppercase English letters and digits. Length of all words are
less than or equal to 3 characters. It’s guaranteed that in the given mysterious table all pairs
are distinct.
Output (Standard Output)
For each test case, output a strange table just like the sample input and output. There are two
secret points you must consider:
 All data fields must contain exactly 3 characters and must be left justified. If the length of
any field data is less than 3, you should add trailing space characters to it.
 Row and column names should appear in ascending lexicographical order.
Sample Input Sample Output
2
9
R1 P1 C1
R1 P2 C2
R1 P3 C3
R1 P4 C4
R2 P1 C5
R2 P5 C6
R2 P6 C7
R2 P7 C8
R3 P5 C9
1
R1 P1 CCC
+---+---+---+---+---+---+---+---+
| |P1 |P2 |P3 |P4 |P5 |P6 |P7 |
+---+---+---+---+---+---+---+---+
|R1 |C1 |C2 |C3 |C4 | | | |
+---+---+---+---+---+---+---+---+
|R2 |C5 | | | |C6 |C7 |C8 |
+---+---+---+---+---+---+---+---+
|R3 | | | | |C9 | | |
+---+---+---+---+---+---+---+---+
+---+---+
| |P1 |
+---+---+
|R1 |CCC|
+---+---+
Hint
The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in
all modern programming languages to compare strings. Formally, a string of length is lexicographically less than
string q of length m, if one of the two statements is correct:
 , and is the beginning (prefix) of string (for example, "aba" is less than string "abaa"),
 for some , here characters in strings are

numbered starting from .

恶心模拟,各种stl。学了一招,把string 用printf的%s输出,方法是printf("%s",s.c_str());

#include <iostream>#include <cstring>#include <cstdio>#include <string>#include <algorithm>#include <map>#include <vector>#include <queue>#include <set>#include <cmath>using namespace std;typedef long long LL;typedef pair<string,string> P;const int maxn = 50 + 5;const int INF = 1000000000;string s1,s2,s3;map<P,string> M;set<string> Se1,Se2;set<string>::iterator it,it2;int main(){    int t;    scanf("%d",&t);    while(t--){        int n;        scanf("%d",&n);        M.clear();        Se1.clear();Se2.clear();        for(int i = 0;i < n;i++){            cin >> s1 >> s2 >> s3;            M[P(s1,s2)] = s3;            Se1.insert(s1);            Se2.insert(s2);        }        for(int i = 0;i < Se2.size()+1;i++) printf("+---");        printf("+\n");        printf("|   ");        for(it = Se2.begin();it != Se2.end();it++){            printf("|%-3s",it->c_str());        }        printf("|\n");        for(int i = 0;i < Se2.size()+1;i++) printf("+---");        printf("+\n");        it = Se1.begin();        for(it = Se1.begin();it != Se1.end();it++){            printf("|%-3s",it->c_str());            for(it2 = Se2.begin();it2 != Se2.end();it2++){                if(M.count(P(*it,*it2)) == 0) printf("|   ");                else printf("|%-3s",M[P(*it,*it2)].c_str());            }            printf("|\n");            for(int i = 0;i < Se2.size()+1;i++) printf("+---");            printf("+\n");        }    }    return 0;}


原创粉丝点击