回复: 10
跳转到指定楼层
上一主题 下一主题
收起左侧

IXL Learning - OA

全局:

2017(4-6月) 码农类General 硕士 全职@ - 内推 - 在线笔试  | | Other | 应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x

  1. #include <iostream>
  2. #include <cassert>
  3. #include <cstring>
  4. #include <climits>
  5. #include <string>
  6. #include <vector>
  7. #include <utility>
  8. using namespace std;

  9. class Solution {
  10. public:
  11.         vector<int> p1(vector<int>& nums) {
  12.                 int OPT[10] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1};
  13.                 vector<int> result;
  14.                 for (const auto &i : nums) {
  15.                         string s = to_string(i);
  16.                         int val = 0;
  17.                         for (const auto &j : s) {
  18.                                 int k = j - '0';
  19.                                 val += OPT[k];
  20.                         }
  21.                         result.push_back(val);
  22.                 }
  23.                 return result;               
  24.         }
  25.        
  26.         vector<int> p2(vector<pair<string, string>>& strprs) {
  27.                 vector<int> result;
  28.                 for (const auto &i : strprs) {
  29.                         const string &s = i.first, &t = i.second;
  30.                         if (s.size() == t.size()) {
  31.                                 int a[256], b[256];
  32.                                 memset(a, 0, sizeof(a));
  33.                                 memset(b, 0, sizeof(b));
  34.                                 for (size_t j = 0; j < s.size(); j++) {
  35.                                         int k = s.at(j) - 0, l = t.at(j) - 0;
  36.                                         a[k]++;
  37.                                         b[l]++;
  38.                                 }
  39.                                 int k = 0;
  40.                                 for (int j = 0; j < 256; j++) {
  41.                                         k += a[j] > b[j] ? a[j] - b[j] : 0;                                       
  42.                                 }
  43.                                 result.push_back(k);
  44.                         }
  45.                         else {
  46.                                 result.push_back(-1);                       
  47.                         }
  48.                 }
  49.                 return result;
  50.         }

  51.         size_t p3(vector<pair<int, int>> steps) {
  52.             size_t x = INT_MAX, y = INT_MAX;
  53.             for (const auto &i : steps) {
  54.                 x = min(x, size_t(i.first));
  55.                 y = min(y, size_t(i.second));
  56.             }
  57.             return x * y;
  58.         }

  59.         vector<string> p4(vector<string>& strs) {
  60.                 vector<string> result;
  61.                 for (const auto &i : strs) {
  62.                         int a = INT_MIN, b = INT_MIN, c = INT_MIN, d = INT_MIN;
  63.                         for (size_t j = 0, n = i.size(); j < n; j++) {
  64.                                 size_t k = j;
  65.                                 if (a == INT_MIN) {
  66.                                         while (j < n and i.at(j) != '/') {
  67.                                                 j++;
  68.                                         }
  69.                                         a = stoi(i.substr(k, j - k));
  70.                                         continue;
  71.                                 }
  72.                                 if (b == INT_MIN) {
  73.                                         while (j < n and i.at(j) != '+') {
  74.                                                 j++;
  75.                                         }
  76.                                         b = stoi(i.substr(k, j - k));
  77.                                         continue;
  78.                                 }
  79.                                 if (c == INT_MIN) {
  80.                                         while (j < n and i.at(j) != '/') {
  81.                                                 j++;
  82.                                         }
  83.                                         c = stoi(i.substr(k, j - k));
  84.                                         continue;
  85.                                 }
  86.                                 if (d == INT_MIN) {
  87.                                         d = stoi(i.substr(k, n - k));
  88.                                         continue;                                       
  89.                                 }
  90.                         }
  91.                         int x = a * d + b * c, y = b * d, r = gcd(x, y);
  92.                         result.push_back(to_string(x / r) + '/' + to_string(y / r));
  93.                 }
  94.                 return result;
  95.         }
  96. private:
  97.         int gcd(int a, int b) {
  98.                 return b == 0 ? a : gcd(b, a % b);
  99.         }
  100. };

  101. int main(void) {
  102.         Solution solution;
  103.         vector<int> nums = {462, 1288, 0, 4, 6, 9, 8}, answer = {2, 4, 1, 1, 1, 1, 2}, result;
  104.         result = solution.p1(nums);
  105.         assert(answer == result);

  106.         vector<pair<string, string>> strprs = {{"aabc", "abcd"}, {"ahahah", "aanannananna"}};
  107.         answer = {1, -1};
  108.         result = solution.p2(strprs);
  109.         assert(answer == result);

  110.         size_t answerL = 2, resultL = 0;
  111.         vector<pair<int, int>> steps = {{2, 3}, {3, 7}, {4, 1}};
  112.         resultL = solution.p3(steps);
  113.         assert(answerL == resultL);

  114.         vector<string> strs = {"1/2+1/3", "1/3+1/6", "3/2+1/2", "0/1+0/10"}, answerStrs = {"5/6", "1/2", "2/1", "0/1"}, resultStrs;
  115.         resultStrs = solution.p4(strs);
  116.         assert(answerStrs == resultStrs);

  117.         cout << "\nPassed All\n";
  118.         return 0;
  119. }
复制代码

补充内容 (2017-5-8 20:09):
g++ -s
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
ignature 不一致 另外我用的C++17 所以直接照抄代码会跪掉....

评分

参与人数 2大米 +33 收起 理由
xiaokeishaobo35 + 3 感谢分享!
夏虫不知雪花 + 30

查看全部评分


上一篇:亚麻LinkedIn社招
下一篇:杰特 backend Karat 店面
🔗
史蒂文421 2017-5-12 07:08:01 | 只看该作者
全局:
感谢楼主分享!想问一下第三题到底是啥意思?
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-5-12 07:13:01 | 只看该作者
全局:
史蒂文421 发表于 2017-5-12 07:08
感谢楼主分享!想问一下第三题到底是啥意思?

不需要准备 直接上
回复

使用道具 举报

🔗
史蒂文421 2017-5-12 07:55:17 | 只看该作者
全局:
LeetCodeOJ 发表于 2017-5-12 07:13
不需要准备 直接上

哈哈哈好!谢谢楼主!你有结果了吗?
回复

使用道具 举报

🔗
史蒂文421 2017-5-12 08:11:27 | 只看该作者
全局:
LeetCodeOJ 发表于 2017-5-12 07:13
不需要准备 直接上

顺便问一下,开摄像头吗?谢谢
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-5-12 08:12:23 | 只看该作者
全局:
史蒂文421 发表于 2017-5-12 08:11
顺便问一下,开摄像头吗?谢谢

不开 用两台电脑 随便搞
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-5-12 08:12:39 | 只看该作者
全局:
史蒂文421 发表于 2017-5-12 08:11
顺便问一下,开摄像头吗?谢谢

我电脑没有摄像头 哈哈哈哈哈
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-5-12 08:13:00 | 只看该作者
全局:
史蒂文421 发表于 2017-5-12 07:55
哈哈哈好!谢谢楼主!你有结果了吗?

目前没有 估计不好说
回复

使用道具 举报

🔗
FF-Ti 2017-8-15 13:28:49 | 只看该作者
全局:
LeetCodeOJ 发表于 2017-5-12 08:12
不开 用两台电脑 随便搞

为什么要开两台电脑呢 不可以同一个电脑滑动页面看嘛
回复

使用道具 举报

🔗
 楼主| LeetCodeOJ 2017-8-15 13:29:36 | 只看该作者
全局:
FF-Ti 发表于 2017-8-15 13:28
为什么要开两台电脑呢 不可以同一个电脑滑动页面看嘛

现在的oa都很厉害 可以看到你离开的了 界面。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表