笔试练习day12

OR63 删除公共字符(简单)(模拟)

删除公共字符_牛客题霸_牛客网 (nowcoder.com)

#include <iostream>
#include<string>
#include<unordered_set>
using namespace std;

int main() {
   string str1;
   unordered_set<char> myset;
   getline(cin,str1);
   char tmp;
   while(cin>>tmp)
   {
        myset.insert(tmp);
   }
   for(auto e : str1)
   {
    if(myset.count(e)) continue;
    cout<<e;
   }
    return 0;
}
// 64 位输出请用 printf("%lld")

JZ52 两个链表的第一个公共结点(中等)(链表)

两个链表的第一个公共结点_牛客题霸_牛客网 (nowcoder.com)

思路1:

链表1走:s1+con+s2

链表2走:s2+con+s1

他们最终会在交点相遇

思路2:

先让长的走到和短的一样长,再一起走判断相遇

/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
    ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
		if(pHead1==nullptr||pHead2==nullptr) return nullptr;
		ListNode* p1=pHead1;
		ListNode* p2=pHead2;
        while(p1!=p2)
		{
			if(p1==nullptr) p1=pHead2;
			else p1=p1->next;
			if(p2==nullptr) p2=pHead1;
			else p2=p2->next;
			
		}
		if(p1->val==p2->val)
		return p1;
		else return nullptr;
    }
};

mari和shiny(简单)(线性dp)

mari和shiny (nowcoder.com)

#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    long long s=0;
    long long sh=0;
    long long shy=0;
    if(str[0]=='s') s=1;
    for(int i=1;i<n;i++)
    {
       
        if(str[i]=='s')
        {
            s += 1;
        }
        if(str[i]=='h')
        {
            sh+=s;
        }
        if(str[i]=='y')
        {
            shy+=sh;
        }
    }
    cout<<shy;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值