第二题:
链接:
https://www.lanqiao.cn/problems/17035/learning/?contest_id=177
我太菜了,不会写,只能看题解
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(string a ,string b)
{
return a+b<b+a;
}
int main()
{
ll n;
cin>>n;
vector<string>s;
for(ll i=1;i<=n;i++)
{
string s1;
cin>>s1;
s.push_back(s1);
}
sort(s.begin(),s.end(),solve);
for(ll i=0;i<n;i++)cout<<s[i];
}
第三题:
链接:https://www.lanqiao.cn/problems/17028/learning/?contest_id=177
方法一:
//找规律
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
string s;
ll T;
cin>>T;
while(T--)
{
cin>>n>>s;
n%=10;
ll sum=s[s.size()-1]-'0'+(s[s.size()-2]-'0')*10;
ll x=0,p=sum;
x=s[s.size()-1]-'0';
x%=2;
p%=4;
if(n==1||n==5||n==6||n==0)
{
cout<<n<<endl;
}
else if(n==2)
{
if(p==1)cout<<2<<endl;
else if(p==2)cout<<4<<endl;
else if(p==3)cout<<8<<endl;
else cout<<6<<endl;
}
else if(n==3)
{
if(p==1)cout<<3<<endl;
else if(p==2)cout<<9<<endl;
else if(p==3)cout<<7<<endl;
else cout<<1<<endl;
}
else if(n==7)
{
if(p==1)cout<<7<<endl;
else if(p==2)cout<<9<<endl;
else if(p==3)cout<<3<<endl;
else cout<<1<<endl;
}
else if(n==8)
{
if(p==1)cout<<8<<endl;
else if(p==2)cout<<4<<endl;
else if(p==3)cout<<2<<endl;
else cout<<6<<endl;
}else if(n==4)
{
if(x==1)cout<<4<<endl;
else cout<<6<<endl;
}
else if(n==9)
{
if(x==1)cout<<9<<endl;
else cout<<1<<endl;
}
}
}
方法二:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+10;
ll quick(ll x,string p)
{
ll res=1;
x%=10;
for(ll i=p.size()-1;i>=0;i--)
{
ll digit=p[i]-'0';//相当于将要求的一个指数拆分成多个指数相乘(应该是)
ll temp=1;
for(ll j=0;j<digit;j++)
{
temp=temp*x%10;
}
res=res*temp%10;
x=x*x%10;
}
return res;
}
int main()
{
ll t;
cin>>t;
while(t--)
{
string s;
ll x;
cin>>x>>s;
cout<<quick(x,s)<<endl;
}
}