PKU_3699 miniSQL

64 篇文章 0 订阅
23 篇文章 0 订阅
模拟题...比较繁琐..过的人代码普遍很长.......

注意方格中的内容"居中"
方格宽度=这一列的最大字符串长度+2
然后居中的时候,设字程是L,方格长K
那么对于字的左边来说,应该有(K-L)/2的空格
右边则要有K-L-(K-L)/2个空格.
注意方格宽度=这一列的最大字符串长度+2
这一列的最大字符串长度并不一定就是项目的名字


miniSQL
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 831
Accepted: 246

Description

Joan is taking an internship at a company these days. Every day she is assigned tons of dull statistical jobs such as counting how many products made by the company values more than $100. In order to have more time to chat with the handsome intern nearby, she asks you to program a clever software that helps her get released from the onerous work.

The software should take as input a table of records together with several queries and for each query output all the records respectively.

Input

The first part of the input is a single line consisting of three integers, m(1 ≤ m ≤ 10), n(1 ≤ n ≤ 10000), k(1 ≤ k ≤ 100) indicating the number of columns in the table, the number of records and the number of queries.

The second part of the input is the description of the table, which consists of m lines. The i-th line of this part consists two strings in the format Column_Name Type which describes the i-th column of the table.

  • Column_Name contains only letters(a-zA-Z), digits(0-9) and underline(_).
  • Type is either "STR" or "INT" indicating the type of this column.

The third part of the input shows the content of the table which contains n lines. The i-th line of this part shows the i-th record in the table which consists of m items.

  • if the type of the i-th column is "INT", the i-th item will be a 32-bit integer.
  • if the type of the i-th column is "STR" , the i-th item will be a string containing only letters(a-zA-Z), digits(0-9) and underline(_).

The last part of the input gives the k queries which are similar to SQL select statements. The query is in the format select Column_List where Condition

  • Column_List contains a list of column names which are separated by a single comma. All the names occured in the description of the table.
  • Condition is in the format Column_Name Op Value
    • Column_Name is one of the column name in the description of the table.
    • if the column's type is "STR", Op is "=". Otherwise it may be "=", "<" or ">".
    • if the column's type is "STR", Value will be a quoted string containing only letters(a-zA-Z), digits(0-9) and underline(_). Otherwise it will be a 32-bit integer.

The size of the input will not exceed 1M bytes.

Output

For each query output a table and a blank line as Sample Output shows.

Sample Input

3 10 4
SID INT
NAME STR
PRIZE INT
1000 Potion 50
1001 Phoenix_Down 150
1002 Remedy 300
1003 Dagger 320
1004 Rod 260
1005 Flame_Staff 1100
1006 Broad_Sword 330
1007 Fork 1100
1008 Javelin 880
1009 Cats_Claws 4000
select SID,NAME,PRIZE where PRIZE>100
select SID,SID where NAME="Dagger"
select PRIZE where NAME="Rod"
select SID,NAME,PRIZE where NAME="Excalibur"

Sample Output


+-----------------------------+
| SID | NAME | PRIZE |
|------|--------------|-------|
| 1001 | Phoenix_Down | 150 |
| 1002 | Remedy | 300 |
| 1003 | Dagger | 320 |
| 1004 | Rod | 260 |
| 1005 | Flame_Staff | 1100 |
| 1006 | Broad_Sword | 330 |
| 1007 | Fork | 1100 |
| 1008 | Javelin | 880 |
| 1009 | Cats_Claws | 4000 |
+-----------------------------+

+-------------+
| SID | SID |
|------|------|
| 1003 | 1003 |
+-------------+

+-------+
| PRIZE |
|-------|
| 260 |
+-------+

+--------------------+
| SID | NAME | PRIZE |
|-----|------|-------|
+--------------------+

Source



  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. #include <string>
  5. using namespace std;
  6. struct vail{string name,type;}V[10],T[10];
  7. struct record{string des[10];}R[10000];
  8. string tmp,key,kv;
  9. int id[10001],idlen,kid,mlen[10001],sid[10],slen;
  10. char op;
  11. int vaa(string aa)
  12. {
  13.     int tmp,tlen=aa.length(),i;
  14.     for(i=tmp=0;i<tlen;i++)tmp=tmp*10+aa[i]-'0';return tmp;
  15. }
  16. int main()
  17. {
  18.     int vcnt,rcnt,ocnt,i,j,k,lt=0,tlen,ti,tttlen;
  19.     char ttmp[256];
  20.     cin>>vcnt>>rcnt>>ocnt;
  21.     for(i=0;i<vcnt;i++)
  22.         cin>>V[i].name>>V[i].type;
  23.     for(i=0;i<rcnt;i++)
  24.         {
  25.             for(j=0;j<vcnt;j++)
  26.                 cin>>R[i].des[j];
  27.         }
  28.     while(ocnt--)
  29.         {
  30.             cin>>tmp>>tmp;
  31.             tlen=tmp.length();
  32.             for(j=ti=lt=0;j<tlen;j++)
  33.                 {
  34.                     if(tmp[j]==',')
  35.                         {
  36.                             ttmp[ti]=0;
  37.                             T[lt++].name=ttmp;
  38.                             ti=0;
  39.                         }
  40.                     else
  41.                         ttmp[ti++]=tmp[j];
  42.                 }
  43.             if(ti)ttmp[ti]=0,T[lt++].name=ttmp;
  44.             cin>>tmp>>tmp;
  45.             tlen=tmp.length();ti=0;
  46.             for(j=0;j<tlen;j++)
  47.                 if(tmp[j]=='='||tmp[j]=='>'||tmp[j]=='<')
  48.                     {
  49.                         ttmp[ti]=0;
  50.                         key=ttmp;
  51.                         break;
  52.                     }
  53.                 else ttmp[ti++]=tmp[j];
  54.             if(tmp[j+1]=='"')
  55.                 {
  56.                     ti=0;
  57.                     for(j+=2;j<tlen;j++)
  58.                         if(tmp[j]=='"'){ttmp[ti]=0;kv=ttmp;break;}
  59.                         else ttmp[ti++]=tmp[j];
  60.                     op='=';
  61.                 }
  62.             else
  63.                 {
  64.                     ti=0;
  65.                     op=tmp[j];
  66.                     for(j++;j<tlen;j++)
  67.                         ttmp[ti++]=tmp[j];
  68.                     ttmp[ti]=0;
  69.                     kv=ttmp;
  70.                 }
  71.             idlen=0;
  72.             for(j=0;j<vcnt;j++)if(key==V[j].name){kid=j;break;}
  73.             for(j=0;j<rcnt;j++)
  74.                 if(op=='=')
  75.                     {
  76.                         if(R[j].des[kid]==kv)
  77.                             id[idlen++]=j;
  78.                     }
  79.                 else if(op=='>')
  80.                     {
  81.                         if(vaa(R[j].des[kid])>vaa(kv))
  82.                             id[idlen++]=j;
  83.                     }
  84.                 else if(vaa(R[j].des[kid])<vaa(kv))
  85.                             id[idlen++]=j;
  86.             slen=0;
  87.             printf("+");
  88.             for(j=0;j<lt;j++)for(k=0;k<vcnt;k++)if(V[k].name==T[j].name)sid[slen++]=k;
  89.             for(j=0;j<slen;j++)
  90.             {
  91.                 mlen[j]=V[sid[j]].name.length();
  92.                 for(k=0;k<idlen;k++)
  93.                     if((tttlen=R[id[k]].des[sid[j]].length())>mlen[j])
  94.                         mlen[j]=tttlen;
  95.                 mlen[j]+=2;
  96.                 for(k=1;k<=mlen[j];k++)printf("-");
  97.                 if(j!=slen-1)printf("-");
  98.             }
  99.             printf("+/n");
  100.             putchar('|');
  101.             for(i=0;i<slen;i++)
  102.                 {
  103.                     j=(mlen[i]-V[sid[i]].name.length())/2;
  104.                     for(k=1;k<=j;k++)putchar(' ');
  105.                     cout<<V[sid[i]].name;
  106.                     j=mlen[i]-j-V[sid[i]].name.length();
  107.                     for(k=1;k<=j;k++)putchar(' ');
  108.                     putchar('|');
  109.                 }
  110.             putchar('/n');
  111.             putchar('|');
  112.             for(i=0;i<slen;i++)
  113.             {
  114.                 for(j=1;j<=mlen[i];j++)
  115.                         putchar('-');
  116.                 putchar('|');
  117.             }
  118.             putchar('/n');
  119.             for(i=0;i<idlen;i++)
  120.                 {
  121.                 putchar('|');
  122.                     for(j=0;j<slen;j++)
  123.                         {
  124.                             tttlen=(mlen[j]-R[id[i]].des[sid[j]].length())/2;
  125.                             for(k=1;k<=tttlen;k++)putchar(' ');
  126.                             cout<<R[id[i]].des[sid[j]];
  127.                             tttlen=mlen[j]-tttlen-R[id[i]].des[sid[j]].length();
  128.                             for(k=1;k<=tttlen;k++)putchar(' ');
  129.                             putchar('|');
  130.                         }
  131.                     printf("/n");
  132.                 }
  133.             printf("+");
  134.             for(i=0;i<slen;i++)
  135.             {
  136.                 for(j=1;j<=mlen[i];j++)
  137.                         putchar('-');
  138.                 if(i!=slen-1)putchar('-');
  139.             }
  140.             printf("+/n/n");
  141.         }
  142.     return 0;
  143. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值