#include<stdio.h>
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
int value[n];
for(int i = 0;i < n;i++)
scanf("%d",&value[i]);
int max = value[0],premax = max;
for(int i = 1;i < n;i++){
if(value[i] > max){
premax = max;
max = value[i];
}
}
if(max != premax) printf("%d %d\n",max,premax);
}
return 0;
}
#include<stdio.h>
int main(){
int t;
int h1,h2,m1,m2;
int time1,time2,dif;
scanf("%d",&t);
while (t--){
//input && initiate
scanf("%d:%d",&h1,&m1);
scanf("%d:%d",&h2,&m2);
//cal
time1=h1*60+m1;
time2=h2*60+m2;
if (time1<=time2)
dif=time2-time1;
else
dif=24*60-(time1-time2);
//output
printf("%d\n",dif);
}
}
#include<stdio.h>
#include<string.h>
//#include<math.h>
int min(int a,int b){
return a < b?a:b;
}
int abs(int x){
if(x < 0)return -x;
else return x;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
char alpha[1000];
scanf("%s",alpha);
int length = strlen(alpha);
int value[1000] = {0};
for(int i = 0;i < length;i++){
for(int j = 0;j < length;j++){
// printf("abs:%d\n",alpha[i]-alpha[j]);
value[i] += min(abs(alpha[i]-alpha[j]),26-abs(alpha[i]-alpha[j]));
}
}
int tmp = value[0];
for(int i = 0;i < length;i++){
if(tmp > value[i])tmp = value[i];
}
printf("%d\n",tmp);
}
return 0;
}
//ac
#include<stdio.h>
#include<string.h>
#include<stack>
using namespace std;
struct TreeNode {//孩子兄弟表示法
char name[21];//记录文件或者目录名
bool flag;//true表示文件,false表示目录
TreeNode *firstChild;
TreeNode *nextSibling;
}tree[105];
int loc;
TreeNode *create() {
tree[loc].firstChild = tree[loc].nextSibling = NULL;
return &tree[loc++];
}
TreeNode *preRootTraverse(TreeNode *root,char name[]) {
stack<TreeNode *> s;
TreeNode *p = root;
while(p != NULL || !s.empty()) {
while(p != NULL) {
if(!strcmp(p->name,name)) {//相同
return p;//返回TreeNode类型的节点
} else {
s.push(p);//只要节点有左孩子就压栈
p = p->firstChild;
}
}
if(!s.empty()) {//左孩子的名字都不相同,再执行兄弟节点
p = s.top();//栈中节点都已经被判断过,取出节点,访问兄弟节点,弹出节点
s.pop();
p = p->nextSibling;//执行大循环
}
}
}
void add(TreeNode *tempRoot,TreeNode *newFileOrDir) {
if(tempRoot->firstChild == NULL) {//左孩子不空就建在左孩子下面
tempRoot->firstChild = newFileOrDir;
} else {
tempRoot = tempRoot->firstChild;//有左孩子,先更新到左孩子,在连接兄弟节点
while(tempRoot->nextSibling != NULL) {//找到兄弟节点为空的兄弟节点
tempRoot = tempRoot->nextSibling;
}
tempRoot->nextSibling = newFileOrDir;
}
}
void listFileOrDir(TreeNode *tempRoot,bool _flag) {
if(tempRoot->firstChild != NULL) {
if(tempRoot->firstChild->flag == _flag) {
printf("%s\n",tempRoot->firstChild->name);
}
tempRoot = tempRoot->firstChild;
while(tempRoot->nextSibling != NULL) {
if(tempRoot->nextSibling->flag == _flag) {
printf("%s\n",tempRoot->nextSibling);
}
tempRoot = tempRoot->nextSibling;
}
}
}
int main() {
int T;
scanf("%d",&T);
while(T--) {
loc = 0;
TreeNode *root = create();//建立根结点
root->flag = false;
strcpy(root->name,"root");
int N;
scanf("%d",&N);//N个操作
while(N--) {
char cmd[11],tempRootName[21];
scanf("%s",cmd);
if(!strcmp(cmd,"CREATEFILE")) {
TreeNode *newFile = create();
newFile->flag = true;
scanf("%s%s",newFile->name,tempRootName);
TreeNode *tempRoot = preRootTraverse(root,tempRootName);//先根遍历,找到与tempRootName相同的节点返回
add(tempRoot,newFile);//在该节点下新建文件
} else {
if(!strcmp(cmd,"CREATEDIR")) {
TreeNode *newDir = create();
newDir->flag = false;
scanf("%s%s",newDir->name,tempRootName);
TreeNode *tempRoot = preRootTraverse(root,tempRootName);
add(tempRoot,newDir);
} else {
if(!strcmp(cmd,"LISTFILE")) {
scanf("%s",tempRootName);
TreeNode *tempRoot = preRootTraverse(root,tempRootName);
listFileOrDir(tempRoot,true);
} else {
scanf("%s",tempRootName);
TreeNode *tempRoot = preRootTraverse(root,tempRootName);
listFileOrDir(tempRoot,false);
}
}
}
}
}
}