#include<bits/stdc++.h>usingnamespace std;int n;constint N =1010;int a[N];intmain(){
cin>>n;for(int i=0;i<n;i++){
cin>>a[i];}int ans =0;for(int i=1;i<n;i++){
ans =max(ans,abs(a[i]-a[i-1]));}
cout<<ans;}
火车购票
实现
#include<bits/stdc++.h>usingnamespace std;constint N =110;int st[N];int n,p;intmain(){
cin>>n;while(n--){bool flag =0;
cin>>p;for(int i=1;i<=100;i+=5){for(int j=0;j<5;j++){int s =0;for(int k=j;k<5;k++){if(st[i+k])break;else s++;}if(s>=p){for(int k=0;k<p;k++){
st[i+j+k]=1;
cout<<i+j+k<<" ";}
flag =1;break;}}if(flag)break;}if(!flag){for(int i=1;i<=100&& p;i++){if(!st[i]){
st[i]=1;
cout<<i<<" ";
p--;}}}
cout<<endl;}}
炉石传说
实现
#include<iostream>#include<algorithm>#include<vector>#include<string>usingnamespace std;int n;structrole{int h;//生命int a;//攻击}p[2][10];voidmove(int k,int idx){for(int i =7; i > idx; i--){
p[k][i]= p[k][i-1];}}voidmove1(int k,int idx){for(int i = idx; i <=7; i++){
p[k][i]= p[k][i +1];}}intmain(){
cin >> n;int idx, h, a;int att, def;int k =0;
p[0][0]={30,0};
p[1][0]={30,0};while(n--){
string op;
cin >> op;if(op =="end") k ^=1;elseif(op =="summon"){
cin >> idx >> a >> h;move(k,idx);
p[k][idx]={ h,a };}else{
cin >> att >> def;
p[k][att].h -= p[!k][def].a;
p[!k][def].h -= p[k][att].a;if(att && p[k][att].h <=0)move1(k, att);if(def && p[!k][def].h <=0)move1(!k, def);}}if(p[0][0].h <=0)puts("-1");elseif(p[1][0].h <=0)puts("1");elseputs("0");for(int k =0; k <2; k++){
cout << p[k][0].h << endl;int s =0;for(int i =1; i <=7; i++){if(p[k][i].h >0) s++;}
cout << s <<" ";for(int i =1; i <= s; i++)
cout << p[k][i].h <<" ";
cout << endl;}return0;}