A:
#include<cstdio>
using namespace std;
int main()
{
long long n;
scanf("%lld",&n);
printf("%lld\n",n%2);
return 0;
}
B:
#include<cstdio>
#include<cstring>
using namespace std;
int mp[15];
char s1[1000005],s2[1000005];
int main()
{
//freopen("testcase10.in","r",stdin);
//freopen("testcase10.out","w",stdout);
scanf("%s%s",s1,s2);
int n=strlen(s1);
int m=strlen(s2);
for(int i=0;i<n;i++)
{
mp[s1[i]-'0']=1;
}
for(int i=0;i<m;i++)
{
if(mp[s2[i]-'0']==1)
mp[s2[i]-'0']=2;
}
int flag=0;
for(int i=0;i<=9;i++)
{
if(mp[i]==2)
{
flag=1;
printf("%d ",i);
}
}
if(flag==0)
{
printf("-1\n");
}
return 0;
}
C:
#include<cstdio>
#include<cstring>
using namespace std;
char s[10005],s0[10005];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s",s0);
int n=strlen(s0);
for(int i=0;i<n;i++)
{
if(s0[i]>='A'&&s0[i]<='Z')s[i]=s0[i]-'A'+'a';
else s[i]=s0[i];
}
int ansl=0,ansr=0,ans=1;
int nowl=0,nowr=0;
for(int i=0;i<n;i++)
{
if(nowr-nowl+1>ans)
{
ans=nowr-nowl+1;
ansl=nowl;
ansr=nowr;
}
if(s[i+1]==s[i]+1||s[i+1]==s[i]-1||(s[i+1]=='z'&&s[i]=='a')||(s[i+1]=='a'&&s[i]=='z'))
{
nowr++;
}
else
{
nowr++;
nowl=nowr;
}
}
for(int i=ansl;i<=ansr;i++)
{
printf("%c",s0[i]);
}
printf("\n");
}
}
D:
#include<cstdio>
using namespace std;
char s1[100005],s2[100005];
int fa[1005];
int find(int x)
{
if(fa[x]!=x)fa[x]=find(fa[x]);
return fa[x];
}
int main()
{
for(int i=0;i<=1000;i++)fa[i]=i;
int n;
scanf("%d",&n);
scanf("%s%s",s1,s2);
int cnt=0;
for(int i=0;i<n;i++)
{
if(s1[i]!=s2[i])
{
int x=find(s1[i]);
int y=find(s2[i]);
if(x!=y)
{
fa[y]=x;
cnt++;
}
}
}
printf("%d\n",cnt);
return 0;
}
来源:CSDN
作者:ShineEternal
链接:https://blog.csdn.net/kkkksc03/article/details/104444430