T1:
A-B B>A时输出0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
int main()
{
ll x,t;
scanf("%lld%lld",&x,&t);
if(t>=x) cout<<"0"<<endl;
else cout<<x-t<<endl;
return 0;
}
T2:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int N=1e5+10;
char ch[N];
int main()
{
scanf("%s",ch+1);
int n=strlen(ch+1);
for(int i=1;i<=n;i+=2) {
cout<<ch[i];
}
cout<<endl;
return 0;
}
T3:
记录每种可能,取最大值即可
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int N=1e5+10;
int ans[N],n,tot=0;
int main()
{
memset(ans,0,sizeof(ans));
scanf("%d",&n);
for(int x,i=1;i<=n;i++) {
scanf("%d",&x);
if(x!=0) {ans[x+1]++;ans[x]++;ans[x-1]++;}
else {ans[x]++;ans[x+1]++;tot++;}
}
int cnt=0;
fo(i,0,N-1) cnt=max(cnt,ans[i]);
cout<<cnt<<endl;
return 0;
}
T4:模拟即可:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e5+10;
int a[N],n,ans=0;
int main()
{
scanf("%d",&n);
fo(i,1,n) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) {
if(a[i]==i) {
if(i==n) swap(a[i],a[i-1]);
else swap(a[i],a[i+1]);
ans++;
}
}
cout<<ans<<endl;
return 0;
}