Comments (3)
确实,最近也做过很多笔试,一般都会让你自己处理输入,但是都是比较常规的,给你n行、1行m个数,然后读取n次、1次读取m个数这样子的,感觉牛客那样子的就够了
from kamacoder-solutions.
同意!!!将数据转换为vector<vector>耗费最多的时间
贴一个比较简单、可能复杂度较高的方法:
std::vector<std::vector<int>> str2vec(const std::string& str) {
std::vector<std::string> rows;
auto start = str.find("[", 1);
auto end = str.find("]");
while (start != std::string::npos) {
rows.emplace_back(str.substr(start + 1, end - start - 1));
start = str.find("[", end + 1);
end = str.find("]", end + 1);
}
int r = rows.size();
int c = std::count(rows[0].begin(), rows[0].end(), ',') + 1;
std::vector<std::vector<int>> nums(r, std::vector<int>(c, 0));
for (int i = 0; i < r; ++i) {
std::stringstream ss(rows[i]);
std::string elem;
int j = 0;
while (getline(ss, elem, ',')) {
nums[i][j++] = std::stoi(elem);
}
}
return nums;
}
from kamacoder-solutions.
第36题这种输入方式是不是有点考察的本末倒置了,[[2,3,1],[2,5,3],[4,2,1]]这种输入方式对于java来说有直接的函数可以用,但是对于c++或者其它语言来说,输入就要花费好长时间来想想怎么处理,可不可以卡尔考虑一下解决一下类似这种题目的输入问题,把问题的考察点重点放在算法而不是输入上?谢谢啦!
java什么函数能直接处理?我java写这题的时候也哼哧哼哧的写了半天,36. 网格路径和 就是力扣原题 剑指 Offer 47. 礼物的最大价值。入门dp,但把这一行字符串的输入 处理成二维数组是真麻烦。
from kamacoder-solutions.
Related Issues (20)
- 请问A+B问题Ⅱ,我把while中的cin>>n写到了while里面为啥不能通过呀 HOT 1
- A+B问题III中给出的Python代码不具有普适性
- 51. 平移二叉树(第七期模拟笔试)C++ HOT 1
- 46. 携带研究材料,go语言代码超时,但我找不到优化的点了 HOT 1
- 共同祖先问题 HOT 1
- [Go] 2. A+B问题II - 看不出来我的答案和正确答案有任何区别,但是说代码不通过 HOT 1
- 21.构造二叉树-使用cin进行输入数据会超时并出现潜在的数组或指针越界,而getline不会,请问一下为什么。 HOT 1
- 1. A+B问题I Java
- go 判题系统或有误 HOT 4
- 一下截图为证,相同代码,go判题第一次判题正确,接着第二次就是运行错误。如此反复循环 HOT 3
- 第28题:子序列中的 k 种字母,测试案例test7的结果一定会超出范围 HOT 6
- 第11题:共同祖先(python) HOT 3
- 模拟笔试数据范围 HOT 2
- Strange input format error in problem 1008. HOT 2
- golang 19题链表反转 超时
- 请问2. A+B问题II,里的while1, try, except有什么作用, 为什么去掉这三会不通过。报错信息如下,看都看不懂呜呜 HOT 6
- 31. 字符串的最大价值 c++版本答案 HOT 1
- 第40题 python当算法相同时会出现内存不足的情况 HOT 4
- 第41题.岛屿数量,C++实现的DFS算法不完善,对于如下测试用力答案有误 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kamacoder-solutions.