}
int flag=1;
for(i=0;i<n;i++){
if(cnt[i]!=i) flag=0;
}
if(flag) printf(“Yes\n”);
else printf(“No\n”);
}
return 0;
}
Problem Description
A stack is a data structure in which all insertions and deletions of entries are made at one end, called the “top” of the stack. The last entry which is inserted is the first one that will be removed. In another word, the operations perform in a Last-In-First-Out (LIFO) manner.
A mergeable stack is a stack with “merge” operation. There are three kinds of operation as follows:
- push A x: insert x into stack A
- pop A: remove the top element of stack A
- merge A B: merge stack A and B
After an operation “merge A B”, stack A will obtain all elements that A and B contained before, and B will become empty. The elements in the new stack are rearranged according to the time when they were pushed, just like repeating their “push” operations in one stack. See the sample input/output for further explanation.
Given two mergeable stacks A and B, implement operations mentioned above.
Input
There are multiple test cases. For each case, the first line contains an integer N(0<N≤105) , indicating the number of operations. The next N lines, each contain an instruction “push”, “pop” or “merge”. The elements of stacks are 32-bit integers. Both A and B are empty initially, and it is guaranteed that “pop” operation would not be performed to an empty stack. N = 0 indicates the end of input.
Output
For each case, print a line “Case #t:”, where t is the case number (starting from 1). For each “pop” operation, output the element that is popped, in a single line.
Sample Input
4
push A 1
push A 2
pop A
pop A
9
push A 0
push A 1
push B 3
pop A
push A 2
merge A B
pop A
pop A
pop A
9
push A 0
push A 1
push B 3
pop A
push A 2
merge B A
pop B
pop B
pop B
0
Sample Output
Case #1:
2
1
Case #2:
1
2
3
0
Case #3:
1
2
3
0
F题题意简单,给一个只有(和)的字符串,是否能更换任意两个位置的括号使这个字符串的所有括号都能匹配。
用栈来做,数组来存没有匹配到的括号,先匹配完所有可以匹配的括号,剩下的处理。
不过要注意:‘()‘ 这种情况不行,因为必须要更换一次。
还有‘))((’是可以通过更换匹配的到的,特判写一下就能过了。
#include
#include
#include
#include
#include
using namespace std;
#define N 100010
stacka;
char s[N],k[N];
int main()
{
int i,j,n,cnt,res,T,l,r;
char x;
scanf(“%d”,&T);
while(T–)
{
scanf(“%d”,&n);
l=0,r=0;
for(i=1;i<=n;i++){
cin>>x;
k[i]=x;
if(x==‘)’) r++;
else l++;
a.push(x);
}
if(n%2!=0||l!=r) {
printf(“No\n”);
continue;
}
if(n2&&k[1]‘(’&&k[2]==‘)’){ printf(“No\n”);continue;}
cnt=n/2,res=0;
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
总结
最后为了帮助大家深刻理解Android相关知识点的原理以及面试相关知识,这里放上相关的我搜集整理的14套腾讯、字节跳动、阿里、百度等2020面试真题解析,我把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包知识脉络 + 诸多细节。
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。
710662715677)]
[外链图片转存中…(img-78IZmb18-1710662715678)]
[外链图片转存中…(img-aIbcBbCA-1710662715678)]
[外链图片转存中…(img-4q19pmYH-1710662715679)]
网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。
[外链图片转存中…(img-5UOQtNqI-1710662715679)]