PAT_A 1109. Group Photo (25)

题目信息

  1. Group Photo (25)
    Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:

The number of people in each row must be N/K (round down to the nearest integer), with all the extra people (if any) standing in the last row;
All the people in the rear row must be no shorter than anyone standing in the front rows;
In each row, the tallest one stands at the central position (which is defined to be the position (m/2+1), where m is the total number of people in that row, and the division result must be rounded down to the nearest integer);
In each row, other people must enter the row in non-increasing order of their heights, alternately taking their positions first to the right and then to the left of the tallest one (For example, given five people with their heights 190, 188, 186, 175, and 170, the final formation would be 175, 188, 190, 186, and 170. Here we assume that you are facing the group so your left-hand side is the right-hand side of the one at the central position.);
When there are many people having the same height, they must be ordered in alphabetical (increasing) order of their names, and it is guaranteed that there is no duplication of names.
Now given the information of a group of people, you are supposed to write a program to output their formation.

Input Specification:

Each input file contains one test case. For each test case, the first line contains two positive integers N (<=10000), the total number of people, and K (<=10), the total number of rows. Then N lines follow, each gives the name of a person (no more than 8 English letters without space) and his/her height (an integer in [30, 300]).

Output Specification:

For each case, print the formation – that is, print the names of people in K lines. The names must be separated by exactly one space, but there must be no extra space at the end of each line. Note: since you are facing the group, people in the rear rows must be printed above the people in the front rows.

Sample Input:
10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159
Sample Output:
Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John

我的代码

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct people
{
    string name;
    int height;
};
bool mysort(const people &p1,const people &p2)
{
    if(p1.height>p2.height)
        return true;
    else if(p1.height==p2.height)
    {
        if(p1.name<p2.name)
            return true;
    }
    return false;
}
int main()
{
    int num=0;
    int row=0;

    people tmp;
    vector<people> p;
    cin>>num>>row;
    for(int i=0;i<num;i++)
    {
        cin>>tmp.name>>tmp.height;  
        p.push_back(tmp);
    }
    sort(p.begin(),p.end(),mysort);
    vector<people> *v=new vector<people>[row];
    int col=num%row+num/row;
    int count=0;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            if(j%2)
                v[i].insert(v[i].begin(),p.at(count));
            else
                v[i].push_back(p.at(count));
            ++count;
        }
        col=num/row;
    }
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<v[i].size();++j)
        {
            cout<<v[i].at(j).name;
                if(j<v[i].size()-1)
                    cout<<" ";
        }
        cout<<endl;
    }
    delete[] v;
    return 0;
}
select distinct a.EMPI_ID, a.PATIENT_NO, a.MR_NO, a.PAT_NAME, a.PAT_SEX, a.PAT_AGE, a.PAT_PHONE_NO, b.DIAG_RESULT, a.ADMIT_DATE, a.DISCHARGE_DEPT_NAME, a.ATTEND_DR from BASIC_INFORMATION a join PA_DIAG b on a.MZZY_SERIES_NO=b.MZZY_SERIES_NO join EXAM_DESC_RESULT_CODE c on a.MZZY_SERIES_NO=c.MZZY_SERIES_NO join DRUG_INFO d on a.MZZY_SERIES_NO=d.MZZY_SERIES_NO join EMR_CONTENT e on a.MZZY_SERIES_NO=e.MZZY_SERIES_NO JOIN TEST_INFO A17 ON a.MZZY_SERIES_NO = A17.MZZY_SERIES_NO where a.PAT_AGE>='18' and (to_char(a.ADMIT_DATE,'YYYY-MM-DD') >= '2021-01-01') AND (b.DIAG_RESULT LIKE '%鼻咽癌%' or b.DIAG_RESULT LIKE '%鼻咽恶性肿瘤%' or b.DIAG_CODE LIKE '%C11/900%') and d.DRUG_NAME not in (select DRUG_NAME FROM DRUG_INFO WHERE DRUG_NAME like '卡培他滨') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%HIV阳性%') and b.DIAG_RESULT NOT IN (SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%充血性心力衰竭%') AND to_char(( A17.TEST_DETAIL_ITEM_NAME = '中性粒细胞' AND A17.TEST_RESULT >= 1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血小板' AND A17.TEST_RESULT >= 100 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '血红蛋白' AND A17.TEST_RESULT >= 9 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '丙氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '天门冬氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐清除率' AND A17.TEST_RESULT > 51 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '肌酐' AND A17.TEST_RESULT <=1.5 ) OR ( A17.TEST_DETAIL_ITEM_NAME = '凝血酶原时间' AND A17.TEST_RESULT <= 1.5 ))语句哪里有问题
06-07
这个 SQL 语句中有一个问题,就是在最后一个 AND 子句中的 to_char() 函数的参数不正确。to_char() 函数需要一个日期或数字类型的参数,但是这里传入的是一个逻辑类型的表达式。 如果你想要在 WHERE 子句中使用逻辑表达式,则可以使用 CASE WHEN 语句来实现。下面是修改后的 SQL 语句: ``` SELECT DISTINCT a.EMPI_ID, a.PATIENT_NO, a.MR_NO, a.PAT_NAME, a.PAT_SEX, a.PAT_AGE, a.PAT_PHONE_NO, b.DIAG_RESULT, a.ADMIT_DATE, a.DISCHARGE_DEPT_NAME, a.ATTEND_DR FROM BASIC_INFORMATION a JOIN PA_DIAG b ON a.MZZY_SERIES_NO = b.MZZY_SERIES_NO JOIN EXAM_DESC_RESULT_CODE c ON a.MZZY_SERIES_NO = c.MZZY_SERIES_NO JOIN DRUG_INFO d ON a.MZZY_SERIES_NO = d.MZZY_SERIES_NO JOIN EMR_CONTENT e ON a.MZZY_SERIES_NO = e.MZZY_SERIES_NO JOIN TEST_INFO A17 ON a.MZZY_SERIES_NO = A17.MZZY_SERIES_NO WHERE a.PAT_AGE >= '18' AND (TO_CHAR(a.ADMIT_DATE, 'YYYY-MM-DD') >= '2021-01-01') AND ( b.DIAG_RESULT LIKE '%鼻咽癌%' OR b.DIAG_RESULT LIKE '%鼻咽恶性肿瘤%' OR b.DIAG_CODE LIKE '%C11/900%' ) AND d.DRUG_NAME NOT IN ( SELECT DRUG_NAME FROM DRUG_INFO WHERE DRUG_NAME LIKE '卡培他滨' ) AND b.DIAG_RESULT NOT IN ( SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%HIV阳性%' ) AND b.DIAG_RESULT NOT IN ( SELECT DIAG_RESULT FROM PA_DIAG WHERE DIAG_RESULT LIKE '%充血性心力衰竭%' ) AND ( CASE WHEN A17.TEST_DETAIL_ITEM_NAME = '中性粒细胞' AND A17.TEST_RESULT >= 1.5 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '血小板' AND A17.TEST_RESULT >= 100 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '血红蛋白' AND A17.TEST_RESULT >= 9 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '丙氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '天门冬氨酸氨基转移酶' AND A17.TEST_RESULT <= 2.5 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '肌酐清除率' AND A17.TEST_RESULT > 51 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '肌酐' AND A17.TEST_RESULT <= 1.5 THEN 'Y' WHEN A17.TEST_DETAIL_ITEM_NAME = '凝血酶原时间' AND A17.TEST_RESULT <= 1.5 THEN 'Y' ELSE 'N' END) = 'Y'; ``` 在最后一个 AND 子句中,使用了 CASE WHEN 语句来判断测试结果是否符合条件。如果测试结果符合条件,则返回 Y,否则返回 N。然后再判断返回值是否等于 Y。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值