360笔试编程题

360笔试题目:

C++简单实现:

 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <math.h>
 4 #include <sstream>
 5 #include <cstring>
 6 #include <vector>
 7 #include <algorithm>
 8 
 9 using namespace std;
10 
11 
12 const int MAXWATCHTIMES = 2001;
13 const int MAXKINDS = 101;
14 int watchFlowers[MAXWATCHTIMES] = {0};
15 int flowerKinds[MAXKINDS] = {0};
16 
17 void getCount(int start, int anEnd, int & resultSingle);
18 
19 int main() {
20     int n;
21     int m;
22     vector<int> result;
23     cin >> n >> m;
24     result.clear();
25     for (int j = 0; j < n; ++j) {
26         cin >> watchFlowers[j];
27     }
28 
29     int Q;
30     int start;
31     int end;
32     int resultSingle = 0;
33     cin >> Q;
34     for (int i = 0; i <  Q; ++i) {
35         cin >> start >> end;
36         getCount(start,end,resultSingle);
37         result.push_back(resultSingle);
38     }
39 
40     vector<int>::iterator it = result.begin();
41     for (;it != result.end(); ++it) {
42         cout << *it << endl;
43     }
44 }
45 
46 void getCount(int start, int anEnd, int & resultSingle) {
47     start--;
48     anEnd--;
49     for (int k = 0; k < 101; ++k) {
50         flowerKinds[k] = 0;
51     }
52     for (int i = start; i <= anEnd; ++i) {
53         flowerKinds[watchFlowers[i]] = 1;
54     }
55 
56     resultSingle = 0;
57     for (int j = 0; j < 101; ++j) {
58         resultSingle += flowerKinds[j];
59     }
60 }

------------------------------------------------通过60%

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------

另附加第三道编程题,未做,留作参考!

转载于:https://www.cnblogs.com/TonvyLeeBlogs/p/9545957.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值