1赚钱
题目地址:https://www.luogu.com.cn/problem/U377638
1 //U377638 赚钱 2 #include <iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 int n,a[200010]; 8 int main() { 9 cin>>n; 10 for(int i=1; i<=n; i++) cin>>a[i]; 11 int mmin=a[1];//记录到目前为止能够买进的最小值 12 int ans=-2e9-1; 13 for(int i=1; i<n; i++) { 14 mmin=min(mmin,a[i]); 15 ans=max(a[i+1]-mmin,ans); 16 } 17 cout<<ans; 18 return 0; 19 }
2回文字符串
题目地址:https://www.luogu.com.cn/problem/U377648
1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 string s; 7 int main() { 8 cin>>s; 9 int ls=s.length(); 10 int ans=0; 11 int l=0,r=ls-1; 12 int f=0; 13 while(l<r) { 14 if(s[l]!=s[r]) {//考虑好几个字母相等的情况 15 string a="",b=""; 16 while(l<r) { 17 a=a+s[l]; 18 b=s[r]+b; 19 l++; 20 r--; 21 if(a==b) { 22 ans+=2; 23 break; 24 } 25 } 26 if(a==b) f=0;//ab ab 27 else f=1;//a code a 28 } else { //目前相等,直接去掉 29 ans+=2; 30 l++; 31 r--; 32 if(l==r) f=1; //a h a 33 else f=0;//a a 34 } 35 } 36 ans+=f; 37 if(ans<=1) cout<<"NO"; 38 else cout<<"YES"<<endl<<ans; 39 return 0; 40 }