noip模擬57(待補)
阿新 • • 發佈:2021-09-22
「2A·2B·2C·2D」
A. 2A
簽到題.
A_code
#include<bits/stdc++.h> using namespace std; namespace BSS { #define ll long long int #define ull unsigned ll #define lf double #define lbt(x) (x&(-x)) #define mp(x,y) make_pair(x,y) #define lb lower_bound #define ub upper_bound #define Fill(x,y) memset(x,y,sizeof x) #define Copy(x,y) memcpy(x,y,sizeof x) #define File(x,y) freopen(#x,"r",stdin),freopen(#y,"w",stdout) #define FILE(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) inline ll read() { int ss=0; bool cit=1; char ch; while(!isdigit(ch=getchar())) if(ch=='-') cit=0; while(isdigit(ch)) ss=(ss<<3)+(ss<<1)+(ch^48),ch=getchar(); return cit?ss:-ss; } } using namespace BSS; char s[201]; ll m,n,flag; ll ans[201] ; inline void Match(){ ll i=1,j=1,k; if(!isdigit(s[i])) flag=0; while(i<=n){ if(isdigit(s[i])){ if(isdigit(s[i+1]) and s[i]=='0') flag=0; while(isdigit(s[i]) and i<=n){ ans[j]=(ans[j]<<3)+(ans[j]<<1)+(s[i]^48); i++; } flag&=(ans[j]<=255),j++; } else{ k=0; while((!isdigit(s[i])) and i<=n){ i++,k++; } if(!(k==1 and s[i-1]=='.')) flag=0; if(j>4 or j==1) flag=0; } } flag&=(j==5); } signed main(){ FILE(ip); scanf("%s",s+1),n=strlen(s+1),flag=1,Match(); if(flag) puts("YES"); else{ puts("NO"); for(int i=1;i<=3;i++){ printf("%lld.",ans[i]>255 ? 255 : ans[i]); } printf("%lld",ans[4]>255 ? 255 : ans[4]); } exit(0); }
B. 2B
簽到題.
B_code
#include<bits/stdc++.h> using namespace std; namespace BSS { #define ll long long int #define ull unsigned ll #define lf double #define lbt(x) (x&(-x)) #define mp(x,y) make_pair(x,y) #define lb lower_bound #define ub upper_bound #define Fill(x,y) memset(x,y,sizeof x) #define Copy(x,y) memcpy(x,y,sizeof x) #define File(x,y) freopen(#x,"r",stdin),freopen(#y,"w",stdout) #define FILE(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) inline ll read() { int ss=0; bool cit=1; char ch; while(!isdigit(ch=getchar())) if(ch=='-') cit=0; while(isdigit(ch)) ss=(ss<<3)+(ss<<1)+(ch^48),ch=getchar(); return cit?ss:-ss; } } using namespace BSS; const ll N=1e4+21; char s[N]; ll m,n,as,ps; ll c[N]; signed main(){ FILE(apstr); scanf("%s",s+1),n=strlen(s+1); for(int i=1;i<=n;i++) c[i]=(s[i]=='A' ? 1 : 2); for(int i=n;i>=1;i--){ if(c[i]&1) as+=(ps<=0),ps-=(ps>0); else ps++; } printf("%lld\n",as+(ps&1)); exit(0); }