思路:
1. 分割字符串,提取數字
2. multimap存儲
3. 遍歷找到相應結果輸出
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<int> arr;
int main()
{
string str;
cin >> str;
if(str ==
"")
return 0;
int x1 =
0;
int x2 =
0;
int int_temp;
string stemp;
while (
true){x2 = str.find(
',', x1);
if(x2 == -
1)
break;stemp = str.substr(x1, x2 - x1);int_temp = atoi(stemp.c_str());arr.push_back(int_temp);x1 = x2 +
1;}stemp = str.substr(x1, str.size()-x1);int_temp = atoi(stemp.c_str());arr.push_back(int_temp);
multimap<int,int> myMultimap;
for(
int i=
0; i<arr.size(); i++){myMultimap.insert( pair<
int,
int>(arr[i], i+
1) );}
int k;
cin >> k;
int count =
0;
for(
auto itemp = myMultimap.rbegin(); itemp!=myMultimap.rend(); itemp++){++count;
if(count == k)
cout << itemp->second << endl;}
return 0;
}
思路:
1.題目要求二叉排序樹轉換為雙鏈表
2.但是,我沒有看懂輸入的樣例。。。。。。
3.直接進行分割字符串,提取數字,set存儲去重,順序輸出
4.沒有AC,過了80%,不知道問題在哪兒
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main()
{
string str;
while(getline(
cin, str)){
set<int> mySet;
if(str ==
"")
return 0;
int x1 =
0;
int x2 =
0;
int int_temp;
string stemp;
while (
true){x2 = str.find(
' ', x1);
if(x2 == -
1)
break;stemp = str.substr(x1, x2 - x1);int_temp = atoi(stemp.c_str());mySet.insert(int_temp);x1 = x2 +
1;}stemp = str.substr(x1, str.size()-x1);int_temp = atoi(stemp.c_str());mySet.insert(int_temp);
int len = mySet.size();
if(len ==
0)
return 0;
auto it=mySet.begin();
for(
int i=
0; i<len-
1; i++){
cout << *it <<
" ";it++;}
cout << *mySet.rbegin();}
return 0;}
總結
以上是生活随笔為你收集整理的OPPO 2019校园招聘C/C++开发工程师(手机方向) 笔试编程题-2018.09.10的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。