1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> #include<string.h> char t[1000]; int n; int tree(int k) { if ((t[2*k]=='#'&&t[2*k+1]=='#')||(2*k>n&&(2*k+1>n))) return 1; else if (2*k<=n&&t[2*k]!='#'&&(2*k+1<=n)&&t[2*k+1]!='#') return tree(2*k)&&tree(2*k+1); else return 0; } int main(){ int i; scanf("%s",t); n=strlen(t); for (i=n;i>0;i--) t[i]=t[i-1]; if (tree(1)) printf("Yes\n"); else printf("No\n"); return 0; }C++ :
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<cstdlib> #include<queue> #include<vector> #define INF 0x3f3f3f3f #define PI acos(-1.0) #define N 1001 #define MOD 123 #define E 1e-6 using namespace std; char s[N]; int main() { cin>>s; int len=strlen(s); s[len]='#'; int flag=true; for(int i=1;i<len;i+=2){ if( (s[i]=='#'&&s[i+1]!='#') || (s[i+1]=='#'&&s[i]!='#') ) { flag=false; break; } } if(flag) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
- 1
信息
- ID
- 1087
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者