首页 > 8-23 爱奇艺笔试

8-23 爱奇艺笔试

1.N!0的个数 -AC
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

//愛妻一 AC
int main()
{
    int N;
    while(cin>>N)
    {
    int num = 0;
    for (int i = 1; i <= N; i++)
    {
        int j = i;
        while (j % 5 == 0)
        {
            num++;
            j /= 5;
        }
    }
    cout<<num<<endl;
    }
}
2.网格寻路 80%
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    string path;
    while(cin>>path)
    {
        int flag=1;
        set<pair<int ,int>>visited;
        visited.insert(make_pair(0,0));
        int x=0;
        int y=0;
        int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
        for(int i=0;i<path.size();i++)
        {
            if(path[i]=='E')
            {
                x=x+dir[0][0];
                y=y+dir[0][1];
            }
            else if(path[i]=='W')
            {
                x=x+dir[1][0];
                y=y+dir[1][1];
            }
            else if(path[i]=='N')
            {
                x=x+dir[2][0];
                y=y+dir[2][1];
            }
            else 
            {
                x=x+dir[3][0];
                y=y+dir[4][1];               
            }

            if(visited.find(make_pair(x,y))==visited.end())//not visited
            visited.insert(make_pair(x,y));
            else {
                cout<<"True"<<endl;
                flag=0;
                break;
            }
        }
        if(flag==1)
        cout<<"False"<<endl;
    }
}

3.括号匹配-AC
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
//AC 
int main()
{
    string s;
    while(cin>>s)
    {
        int flag=1;
        vector<char>v;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='(' || s[i]=='{' || s[i]=='[')
            v.push_back(s[i]);
            else 
            {
                if(v.size()==0)
                {
                    flag=0;
                    break;
                }
                else 
                {
                    if( (s[i]==')'&&v[v.size()-1]=='(') ||  (s[i]=='}'&&v[v.size()-1]=='{') || (s[i]==']'&&v[v.size()-1]=='[') )
                    {
                        v.pop_back();
                    }
                    else {
                        flag=0;
                        break;
                    }
                }
            }
        }
        if(flag==1 && v.size()==0) cout<<"True"<<endl;
        else cout<<"False"<<endl;
    }
}




全部评论

(4) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐