版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38262266/article/details/86625632
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;
cin>>T;
while(T--)
{
int max_value = 0;
int f_value = 0;
int mid_value = 0;
int n;
cin>>n;
while(n--)
{
int key;
cin>>key;
mid_value = key;
if(mid_value>max_value)
{
f_value = max_value;
max_value = mid_value;
continue;
}
if(mid_value>f_value&&mid_value<max_value)
{
f_value = mid_value;
}
}
cout<<max_value<<" "<<f_value<<endl;
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int deal(char s[],int from,int to)
{
int i=from,num=s[from]-'0';
i++;
while(true)
{
if(i<=to)
{
num=num*10+(s[i]-'0');
i++;
}
else
break;
}
return num;
}
int main()
{
int tes,m;
while(~scanf("%d",&tes))
{
while(tes--)
{
char s1[8],s2[8];
scanf("%s",s1);
scanf("%s",s2);
int num=0,pos1,pos2;
if(s1[1]==':')
pos1=1;
else if(s1[2]==':')
pos1=2;
if(s2[1]==':')
pos2=1;
else if(s2[2]==':')
pos2=2;
int hour1=deal(s1,0,pos1-1);
int hour2=deal(s2,0,pos2-1);
int minu1=deal(s1,pos1+1,strlen(s1)-1);
int minu2=deal(s2,pos2+1,strlen(s2)-1);
if(hour1<=hour2)
{
num+=(hour2-hour1)*60;
}
else if(hour1>hour2)
{
num+=(24-(hour1-hour2))*60;
}
if(minu1<=minu2)
{
num+=minu2-minu1;
}
else if(minu1>minu2)
{
if(num==0)
num=24*60;
num-=60;
num+=(60+minu2)-minu1;
}
printf("%d\n",num);
}
}
return 0;
}
#include<stdio.h>
#include<cmath>
#include<string.h>
#define min(a,b) a<b?a:b
#define clr(a) memset(a,0,sizeof a)
using namespace std;
//先计算出每个字母转化为其他字母的耗费来,再统计出每个字母各出现了多少次,然后枚举所有的变化即可。
int main()
{
int t,i,j,a[26],b[26][26],ans,tmp;
char str[1001];
for(i=0; i<26; i++)
for(j=0; j<26; j++)
b[i][j]=min(abs(i-j),26-abs(i-j));
for(scanf("%d",&t); t--;)
{
scanf("%s",str);
clr(a);
ans=999999999;
for(i=0; str[i]; i++)
a[str[i]-'a']++;
for(i=0; i<26; i++)
{
tmp=0;
for(j=0; j<26; j++)
tmp+=a[j]*b[j][i];
ans=min(ans,tmp);
}
printf("%d\n",ans);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef struct
{
string name;
int father;
int is_dir;
int time;
} node;
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
node f[n+1];
for(int i=0; i<=n; i++)
{
f[i].name="";
f[i].father=-1;
f[i].is_dir=-1;
f[i].time=-1;
}
f[0].name="root";
f[0].is_dir=1;
f[0].time=0;
int k = 1;
int lp = n;
while(lp--)
{
string s;
cin>>s;
if(s=="CREATEFILE")
{
string c,d;
cin>>c>>d;
for(int i=0; i<n; i++)
{
if(f[i].name==d)
{
f[k].name=c;
f[k].father=i;
f[k].is_dir=0;
f[k].time=k;
k++;
break;
}
}
}
if(s=="CREATEDIR")
{
string c,d;
cin>>c>>d;
for(int i=0; i<n; i++)
{
if(f[i].name==d)
{
f[k].name=c;
f[k].father=i;
f[k].is_dir=1;
f[k].time=k;
k++;
}
}
}
if(s=="LISTFILE")
{
string c;
cin>>c;
int num;
for(int i=0; i<n; i++)
{
if(f[i].name==c)
{
num = i;
break;
}
}
for(int i=0; i<n; i++)
{
if(f[i].is_dir==0&&f[i].father==num)
{
cout<<f[i].name<<endl;
}
}
}
if(s=="LISTDIR")
{
string c;
cin>>c;
int num;
for(int i=0; i<n; i++)
{
if(f[i].name==c)
{
num=i;
break;
}
}
for(int i=0; i<n; i++)
{
if(f[i].is_dir==1&&f[i].father==num)
{
cout<<f[i].name<<endl;
}
}
}
// for(int i=0;i<k;i++)
// {
// cout<<"name: "<<f[i].name<<" is_dir: "<<f[i].is_dir<<" father: "<<f[i].father<<" time: "<<f[i].time<<endl;
// }
}
}
return 0;
}