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%
-------------------------------------------------------------------------------------------------------------------------------------------------------------
另附加第三道编程题,未做,留作参考!
专注搬砖,擅长搬砖砸自己的脚~~~
Email:
ltwbuaa@163.com