码迷,mamicode.com
首页 > 其他好文 > 详细

笔试编程---快手实习题目

时间:2018-04-20 23:38:12      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:img   highlight   mes   getchar   cout   分享图片   coder   discus   can   

第一题 快速幂技术分享图片

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long LL;
 
LL dfs(LL x, LL y, LL N)
{
    if (y == 0)
        return 1;
    LL ret = dfs(x, y / 2, N);
    if (y % 2 == 0)
        return ret * ret % N;
    return ret * ret * x % N;
}
 
int main()
{
    LL x, y, N;
    cin >> x >> y >> N;
    cout << dfs(x, y, N) << endl;
    return 0;
}
  

  第二题二分查找

 

技术分享图片

#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int x;
    char c;
    vector<int> arr;
    while (true) {
        scanf("%d", &x);
        arr.push_back(x);
        if (getchar() == ‘\n‘)
            break;
    }
    scanf("%d", &x);
    printf("%u\n", lower_bound(arr.begin(), arr.end(), x) - arr.begin());
    return 0;
}

  链接 来源于牛客网




 

笔试编程---快手实习题目

标签:img   highlight   mes   getchar   cout   分享图片   coder   discus   can   

原文地址:https://www.cnblogs.com/gaochaochao/p/8893877.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!