OR63 删除公共字符
题目链接:删除公共字符_牛客题霸_牛客网 (nowcoder.com)
思路: 直接记录第二个字符串的字母 遍历第一个字符串即可。
AC code:
#include <iostream>
#include<string>
using namespace std;
const int N = 200;
bool st[N];
string a,b;
string ans;
int main()
{
getline(cin, a);
getline(cin, b);
for(auto& t : b)
st[t] = 1;
for(auto&t : a)
if(!st[t])
ans += t;
cout << ans << endl;
return 0;
}
JZ52 两个链表的第一个公共结点
题目链接:两个链表的第一个公共结点_牛客题霸_牛客网 (nowcoder.com)
思路:开出两个新节点 分别遍历phead1 和 2 , 当为空是 换成对方的路再走一遍 当相等时为第一个公共节点。
AC code:
class Solution
{
public:
ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2)
{
ListNode* l1 = pHead1;
ListNode* l2 = pHead2;
while(l1 != l2)
{
l1 = !l1 ? pHead2: l1->next;
l2 = !l2 ? pHead1: l2->next;
}
return l1;
}
};
mari和shiny
题目链接:mari和shiny (nowcoder.com)
思路:
本题为子序列 不是子串 组成的shy 在原串中可以不连续。
b 为 ”s“ 出现的次数
k 为 ”sh“出现的次数
AC code:
#include<iostream>
#include<string>
using namespace std;
string a;
int n;
long long int ans;
long long int b,c,k;
int main()
{
cin >> n >> a;
for(auto& t : a)
{
if(t == 's') b ++;
if(t == 'h')
{
c = b; k += b;
}
if(t == 'y')
ans += k;
}
cout << ans << endl;
return 0;
}