4.21打卡
Posted jiuxiao123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了4.21打卡相关的知识,希望对你有一定的参考价值。
输入描述:
第二行 nnn 个正整数,第 iii 个表示 ai(1≤ai≤109)a_i(1\\le a_i\\le10^9)ai(1≤ai≤109)。
输出描述:
输出一行一个正整数,表示答案。
#include<iostream>
using namespace std;
void quick_sort(long long q[], long long l, long long r)
if (l >= r) return;
long long i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j)
do i ++ ; while (q[i] < x);
do j -- ; while (q[j] > x);
if (i < j) swap(q[i], q[j]);
quick_sort(q, l, j), quick_sort(q, j + 1, r);
int main()
long long n,i;
cin >> n;
long long a[n];
for(i=0;i<n;i++)
cin >> a[i];
quick_sort(a,0,n-1);
long long p=n/2;
for(i=n-2;i>=0;i-=2)
a[i]=0;
long long sum=0;
for(i=0;i<n;i++)
sum+=a[i];
cout << sum;
二、
SQL 统计每日上班打卡和下班打卡语句
有以上员工打卡记录表
其中
Card_No为考勤卡号
Atte_time 为打卡时间
DoorInout为上班或下班,1为上班,0位下班
想统计没人每天最早上下班打卡,和其他上下班打卡 各去4笔 如不足则为空
如以下样式的表
-----------------------------------------
考勤卡号 日期 上班打卡 上班打卡1 上班打卡2 上班打卡3 下班打卡 下班打卡1 下班打卡2 下班打卡310890895 2013-08-10 16:04 20:24 NULL NULL 19:43 2013-08-11 00:46 NULL NULL10890895 2013-08-11 16:04 19:45 20:18 NULL NULL NULL NULL NULL
如果下班在第二天3点以内的也统计入下班打卡中下班打卡早于最早上班打卡的数据忽略
CREATE TABLE AtteTime
(
Card_No VARCHAR(10) ,
Atte_Time DATETIME ,
DoorInOut BIT
)
select A1.card_no,
A1.atte_time as "上班时间",
A2.atte_time as "上班时间1",
A3.atte_time as "上班时间2",
A4.atte_time as "上班时间3",
B1.atte_time as "下班时间",
B2.atte_time as "下班时间1",
B3.atte_time as "下班时间2",
B4.atte_time as "下班时间3"
from (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 1) A1
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 2) A2
on A1.card_no = A2.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 3) A3
on A1.card_no = A3.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time) as In_ID
from attetime
where doorinout = 1) T
where T.In_ID = 4) A4
on A1.card_no = A4.card_no
full join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 1) B1
on A1.card_no = B1.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 2) B2
on A1.card_no = B2.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 3) B3
on A1.card_no = B3.card_no
left join (select card_no, atte_time
from (select card_no,
atte_time,
ROW_NUMBER() over(partition by card_no order by atte_time desc) as Out_ID
from attetime
where doorinout = 0) T
where T.Out_ID = 4) B4
on A1.card_no = B4.card_no
投入验证数据如下:
执行结果如下:
参考技术A 这是在oracle数据库下做的,不知道你是什么数据库,给你提供一下思路select
card_no,
attr_date,
to_char(atte_time,'HH24:MI')tim,
doorinout,
rn
from (
select
card_no,
attr_date,
atte_time,
doorinout,
ROW_NUMBER() OVER(PARTITION BY card_no,attr_date,doorinout ORDER BY atte_time asc) rn
from(
select
card_no,
(
case
when doorinout=1
then to_date(to_char(atte_time,'yyyy-MM-dd'),'yyyy-MM-dd')
when (doorinout=0 and to_number(to_char(atte_time,'HH24'))<3)
then (to_date(to_char(atte_time,'yyyy-MM-dd'),'yyyy-MM-dd')-1)
else to_date(to_char(atte_time,'yyyy-MM-dd'),'yyyy-MM-dd')
end
)attr_date,
atte_time,
doorinout
from AtteTime
) tmp order by card_no,atte_time asc,doorinout desc
) where rn < 5 参考技术B 能不能来一份数据 这么凭空想 或者构造数据 太麻烦 一些代表性的数据 就行。还有问题要描述清楚 :1)各 取 4笔还是各 去 4 笔,少了为空,多了呢?取时间早的还是时间晚的。
2) 没人每天是什么意思
3) 不经过调试 谁也不能保证自己写出的语句是100%正确的,给点代表性的数据。追问
上班,下班各去4笔数据,少了留空,多了去出去最早前4笔
每人每天的数据意思就是按照考勤号和日期进行分组
数据:字数限制放不上来
给分代表性的数据 错别字还是少点好
追问数据字数太长了放不上来,百度HI上给你吧.
以上是关于4.21打卡的主要内容,如果未能解决你的问题,请参考以下文章