美团已跪。。两个编程题,卡在第一个编程题目的多行输入上。。

如题,有没有大神给讲解一下这个多行输入怎么处理的?#美团#
全部评论
看到这个输入格式我直接用 python 了 X = [int(x) for x in sys.stdin.readline().strip().split(',')]
点赞 回复 分享
发布于 2016-09-11 16:07
string line; getline(cin, line); isstream ss(line); vector<int> nums; int num; while(ss>>num){ nums.push_back(num); }
点赞 回复 分享
发布于 2016-09-11 15:50
这题有坑啊,题意说按逗号分隔,然后给出的输入样例是按空格的....
点赞 回复 分享
发布于 2016-09-11 16:13
被他这个带逗号的输入搞哭了
点赞 回复 分享
发布于 2016-09-11 15:46
Scanner in = new Scanner(System.in); String line = in.nextLine(); String strs[] = line.split(","); 最后将strs转int就行了
点赞 回复 分享
发布于 2016-09-11 15:55
先读进字符串 然后取出数字放进数组 string str; getline(cin,str); vector<int> nums; for(int i=0;i<str.size();i++) if(str[i]>='0' && str[i]<='9')   nums.push_back(str[i]-'0'); 最后从数组nums中取数据 仅供参考,不喜勿喷
点赞 回复 分享
发布于 2016-09-11 15:46
vector<int> split(string& s, char delim) { vector<int> elems; size_t pos = 0; size_t len = s.length(); while (pos < len) { int find_pos = s.find(delim, pos); if (find_pos < 0) { elems.push_back(atoi(s.substr(pos, len - pos).c_str())); break; } elems.push_back(atoi(s.substr(pos, find_pos - pos).c_str())); pos = find_pos + 1; } return elems; } int main() { char inout_num[1000], delete_num[3]; cin.getline (inout_num, 1000); string tmp(inout_num); vector<int> rec = split(tmp, ' '); ... } 这么干的...
点赞 回复 分享
发布于 2016-09-11 15:47
附加说明。。Java如何处理。。
点赞 回复 分享
发布于 2016-09-11 15:53
字符串流
点赞 回复 分享
发布于 2016-09-11 15:53
String s = Scanne.nextLine(); int T = Integer.valueOf(s);
点赞 回复 分享
发布于 2016-09-11 15:55
美团第二题直接是个BigInteger,不过为什么描述里面说是用“,”分割两个字符串,结果给的输入是空格分隔的- -你这是在逗我吗(最后交的按“,”处理了)
点赞 回复 分享
发布于 2016-09-11 16:05
多叉树如何表示???
点赞 回复 分享
发布于 2016-09-11 16:07
谁知道js怎么输入多行数据,求告知啊!
点赞 回复 分享
发布于 2016-09-11 16:08
int n; cin>>n; if(n>0 && n<20) { vector<vector<int> > v(n); for(int i=0;i<n;i++) { int num; while(cin>>num) v[i].push_back(num); } } 不知道这样可不可以?
点赞 回复 分享
发布于 2016-09-11 16:17
//自己重新写了一个Java的,按Ctrl-z可以结束,基本思路是用位图来实现快速发现根节点。然后 //多叉树的存储为链表结构 import java.io.*; import java.util.*; class Node { int val; Node child; Node next; Node(int v) { val = v; child = null; next = null; } } public class Build { public static void myTraverse(Node root){ Node p = root; //hierarchy traverse while(p != null){ //cur root System.out.print(p.val + " "); //siblings while(p.next != null){ System.out.print(p.next.val + " "); p = p.next; } //child if(p.child != null){ p = p.child; } else{ break; } } } public static void main(String args[]) { Scanner in = new Scanner(System.in); //bitmap //save every node //find element quickly Node[] arr = new Node[101]; for (int i = 0; i < 101; i++) { arr[i] = null; } Node coreRoot = null; int count = 0; //Ctrl-z end input while (in.hasNextLine()) { String line = in.nextLine(); String strs[] = line.split("\\s+"); Node root = null; for (int i = 0; i < strs.length; i++) { int num = Integer.valueOf(strs[i]); //cur root if (i == 0) { if (arr[num] == null) { Node temp = new Node(num); arr[num] = temp; } root = arr[num]; } //this level siblings else { Node temp = null; if (arr[num] == null) { temp = new Node(num); arr[num] = temp; } temp = arr[num]; Node p = root; while (p.next != null) { p = p.next; } p.next = temp; } } //core root if (count == 0) { coreRoot = root; } count += 1; } myTraverse(coreRoot); } }
点赞 回复 分享
发布于 2016-09-11 16:40

相关推荐

码农烧烤880:兄弟你是我今天看到的最好看的简历(我说的是简历风格跟简历书写)把985 211再搞亮一点。投boss就说;您好,我华科(985)研二在读,本科211。对您的岗位很感兴趣,希望能获得一次投递机会。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务