22-23(2)第1次线上赛
日期-1
跳转链接
代码
#include<iostream>
#include<cstdio>
using namespace std;
string mm[]={"Jan.","Feb.","Mar.","Apr.","May","Jun.","Jul.","Aug.","Sept.","Oct.","Nov.","Dec."};
int main()
{
int n;
cin>>n;
while(n--)
{
int y,m,d;
scanf("%d%d%d",&y,&m,&d);
cout<<mm[m-1]<<" "<<d<<", "<<y<<endl;
}
return 0;
}
输出-1
跳转链接
代码
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int a,b;
scanf("%d%d",&a,&b);
int ans=a>b?2*a:2*b;
printf("%d\n",ans);
}
return 0;
}
合条件的数-1
跳转链接
代码
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int a,b;
scanf("%d%d",&a,&b);
int ans = a > b ? 1: b / a + 1; //a>b时c肯定为1,a<=b时c=b/a+1
printf("%d\n",ans);
}
return 0;
}
星号阵列-25
跳转链接
代码
#include<iostream>
#include<cstdio>
using namespace std;
bool isprime(int n)
{
if(n==1) return false;
for(int i=2;i*i<=n;i++)
if(n%i==0) return false;
return true;
}
int main()
{
int a;
scanf("%d",&a);
while(true)
{
for(int i=0;i<a;i++)
printf("*");
puts("");
if(a==1||a==2) break;
a--;
while(!isprime(a)) a--;
}
return 0;
}
排序-1
跳转链接
要点
vector容器+sort自定义排序+快速找因子
代码
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
bool cmp(PII p1,PII p2)
{
if(p1.second!=p2.second)
return p1.second>p2.second;
return p1.first<p2.first;
}
int main()
{
int n;
cin>>n;
while(n--)
{
int m;
scanf("%d",&m);
vector<PII> v;
for(int i=0;i<m;i++)
{
int x;
scanf("%d",&x);
int sum=0;
for(int j=1;j*j<=x;j++)
{
if(x%j==0)
{
if(j%2!=0) sum+=j;
if(x/j%2!=0&&x/j!=j) sum+=x/j;
}
}
v.push_back({x,sum});
}
sort(v.begin(),v.end(),cmp);
for(auto it=v.begin();it!=v.end();it++)
{
if(it!=v.begin()) cout<<" ";
printf("%d",it->first);
}
puts("");
}
return 0;
}
11进制
跳转链接
要点
辗转相除法
代码
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int a;
scanf("%d",&a);
string ans;
do
{
int x=a%11;
if(x==10) ans="A"+ans;
else ans=(char)(x+'0')+ans;
a/=11;
}while(a);
cout<<ans<<endl;
}
return 0;
}