Codeforces Round #629 (Div. 3)
1328A
顺序结构
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int T; long long a,b,t;
for(scanf("%d",&T);T;--T)
{
cin>>a>>b;
if(a%b) t=a/b,cout<<b*t-a+b<<endl;
else puts("0");
}
return 0;
}
1328B
和\(CSP2019-S~D1~T1\)很像,可是由于我的粗心大意,查错查了\(10minuts\),还交了三次,痛心遗憾
#include<iostream>
#include<cstdio>
using namespace std;
void Solve1(unsigned long long k)
{
if(k==1) printf("abb");
if(k==2) printf("bab");
if(k==3) printf("bba");
}
void Solve2(unsigned long long n,unsigned long long k)
{
unsigned long long id=n-k+1;
for(int i=1;i<=n;++i)
if(i==id) putchar('b');
else putchar('a');
}
void Dfs(unsigned long long n,unsigned long long k)
{
if(n==3) {Solve1(k);return;}
unsigned long long m;
if(n&1) m=((n-1)>>1)*(n-2);
else m=((n-2)>>1)*(n-1);
if(k<=m) putchar('a'),Dfs(n-1,k);
//一定是k<=m,不能写成k<m!!! 坑死我了!!!
else putchar('b'),Solve2(n-1,k-m);
}
int main()
{
int T; unsigned long long n,k;
for(scanf("%d",&T);T;--T)
{
cin>>n>>k;
Dfs(n,k),putchar('\n');
}
return 0;
}
1328C
简单地贪心与繁杂的字符串处理
#include<iostream>
#include<cstdio>
using namespace std;
void Read(int &x)
{
x=0; char c=getchar();
while(c<'0'||c>'9') c=getchar();
x=c-'0';
}
int main()
{
int T,flag;
int n,num; string s;
for(scanf("%d",&T);T;--T)
{
scanf("%d",&n); s="",flag=0;
for(int i=1;i<=n;++i)
{
Read(num);
if(flag)
{
putchar('0');
if(num==0) s+='0';
if(num==1) s+='1';
if(num==2) s+='2';
}
else{
if(num==0) {putchar('0'); s+='0';}
if(num==1) {putchar('1'); s+='0'; flag=1;}
if(num==2) {putchar('1'); s+='1';}
}
} putchar('\n');
cout<<s<<endl;
}
return 0;
}
本文作者:OItby @ https://www.cnblogs.com/hihocoder/
未经允许,请勿转载。