intjudge(char ch) { if (ch>='A' && ch<='Z') return1; if (ch>='a' && ch<='z') return2; if (ch>='0' && ch<='9') return3; if (ch==' ') return4; return-1; }
boolindepend(char s[],char st[],int &k) { int L = k,R = k+strlen(st)-1; if (L<0 || R>=strlen(s)) return0; for (int i=0;i<(int)strlen(st);i ++) if (s[k+i] != st[i]) return0; bool flag; if (L==0 || judge(s[L-1])==4 || judge(s[L-1])==-1) flag = 1; else flag = 0; if (R==strlen(s)-1 || judge(s[R+1])==4 || judge(s[R+1])==-1) flag &= 1; else flag = 0; if (flag) k=R; return flag; }
voidwork(char s[]) { cout << "AI: "; int len = strlen(s),L,R; for (int i=0;i<len;i ++) if (s[i]!=' ') { L = i; break; } for (int i=len-1;i>=0;i ++) if (s[i]!=' ') { R = i; break; } //删除首尾空格 char news[M]=""; len = 0; //新生成字符串长度 for (int i=L;i<=R;i ++) { if (judge(s[i])==1 && s[i]!='I') s[i] = s[i]-'A'+'a'; //大写转小写 if (s[i]=='?') s[i] = '!'; //?转! if (judge(s[i])==4 && len!=0 && news[len-1]==' ') continue; //删除连续空格 if (len!=0 && news[len-1]==' ' && judge(s[i])==-1) len --; //删除标点符号前的空格 news[len ++] = s[i]; } for (int i=0;i<(int)strlen(news);i ++) { if (independ(news,"can you",i)) cout << "I can"; elseif (independ(news,"could you",i)) cout << "I could"; elseif (independ(news,"I",i) || independ(news,"me",i)) cout << "you"; else cout << news[i]; } //词汇替换 cout << endl; //cout << news <<endl; }
intmain() { //freopen("L1-8.in","r",stdin); scanf("%d\n",&n); while (n --) { cin.getline(s,sizeof s); cout << s << endl; work(s); } return0; }
constint M = 125,N = 1e5+7; int n,m,dep[N]; map <string,int> maps; structnode { char name[M],fname[M]; int sex; } h[N];
intgf(int x){return maps[string(h[x].fname)];}
intLCA(int x,int y)//垃圾一步步求LCA方法,想用logn方法我不拦你 { while (dep[x]>dep[y]) x = gf(x); while (dep[x]<dep[y]) y = gf(y); while (x!=y) x = gf(x),y = gf(y); return x; }
intquery(char s1[],char s2[],char s3[],char s4[]) { if (maps[string(s1)]==0 || maps[string(s3)]==0) return-2; int L = maps[string(s1)],R = maps[string(s3)]; //找节点编号 if (h[L].sex==h[R].sex) return-1; //同性恋 int id = LCA(L,R); //if (id==L || id==R) return 0; if (dep[R]-dep[L]==4) return1; //特判代码,不然有一个点会挂 if ((dep[L]-dep[id]<4 || dep[R]-dep[id]<4) && id) return0; elsereturn1; //判断两个人与他们最近公共祖先的关系,相差了几代 }
intdfs(int x)//生成每个人所处于树的深度 { if (x==0) return1; if (dep[x]) return dep[x]; return dep[x] = dfs(gf(x))+1; }
intmain() { //freopen("L2-2.in","r",stdin); cin >> n; for (int i=1;i<=n;i ++) { cin >> h[i].name >> h[i].fname; char ch = h[i].fname[strlen(h[i].fname)-1]; if (ch=='m' || ch=='n') h[i].sex = 1; else h[i].sex = 0; if (ch=='m' || ch=='f') h[i].fname[strlen(h[i].fname)-1] ='\0'; if (ch=='n') h[i].fname[strlen(h[i].fname)-4] = '\0'; if (ch=='r') h[i].fname[strlen(h[i].fname)-7] = '\0'; maps[string(h[i].name)] = i; //映射此人名字及其编号 //cout << h[i].name << " " << h[i].fname << " " << h[i].sex << endl; } //字符串处理,标记男女 for (int i=1;i<=n;i ++) dfs(i); //为了生成每个人所在树的深度。也就是有多少个祖先 cin >> m; for (int i=1;i<=m;i ++) { char s1[M],s2[M],s3[M],s4[M]; cin >> s1 >> s2 >> s3 >> s4; int t = query(s1,s2,s3,s4); if (t==-2) cout << "NA" << endl; if (t==-1) cout << "Whatever" << endl; if (t==0) cout << "No" << endl; if (t==1) cout << "Yes" << endl; } return0; }
intmain() { //freopen("L2-4.in","r",stdin); cin >> n >> m >> k; for (int i=1;i<=k;i ++) { int now = 0; bool flag = 1; s[0] = 0; for (int i=1;i<=n;i ++) { if (s[0]>m) flag = 0; while (s[0] && s[s[0]]==now+1) now ++,s[0] --; //弹出栈顶元素,while有可能会出去很多元素 int t; cin >> t; if (t==now+1) //是否不用存到栈中,直接出去 { now ++; continue; } s[++ s[0]] = t; //压栈 } while (s[0] && s[s[0]]==now+1) now ++,s[0] --; //结束了在执行出栈操作一次 flag = flag && !s[0]; if (flag) cout << "YES" << endl; else cout << "NO" << endl; } return0; }