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

如题,有没有大神给讲解一下这个多行输入怎么处理的?#美团#
全部评论
看到这个输入格式我直接用 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
Scanner in = new Scanner(System.in); String line = in.nextLine(); String strs[] = line.split(","); 最后将strs转int就行了
点赞 回复 分享
发布于 2016-09-11 15:55
被他这个带逗号的输入搞哭了
点赞 回复 分享
发布于 2016-09-11 15:46
//自己重新写了一个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
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
谁知道js怎么输入多行数据,求告知啊!
点赞 回复 分享
发布于 2016-09-11 16:08
多叉树如何表示???
点赞 回复 分享
发布于 2016-09-11 16:07
美团第二题直接是个BigInteger,不过为什么描述里面说是用“,”分割两个字符串,结果给的输入是空格分隔的- -你这是在逗我吗(最后交的按“,”处理了)
点赞 回复 分享
发布于 2016-09-11 16:05
String s = Scanne.nextLine(); int T = Integer.valueOf(s);
点赞 回复 分享
发布于 2016-09-11 15:55
字符串流
点赞 回复 分享
发布于 2016-09-11 15:53
附加说明。。Java如何处理。。
点赞 回复 分享
发布于 2016-09-11 15:53
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
先读进字符串 然后取出数字放进数组 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

相关推荐

不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
就前几天旅游的时候,打开抖音就经常刷到这类视频:以前是高学历学生、老师、主持人,现在做着团播、擦边主播的工作,以及那些经过精心包装的“职业转型”故事——从铺天盖地的VLOG到所谓的“04年夜场工作日记”,这些内容在初中升学、高考放榜等关键时间节点持续发酵。可以说非常直接且精准地在潜移默化地影响着心智尚未成熟的青少年,使其对特殊行业逐渐脱敏。那我就想问了:某些传播公司、平台运营者甚至某些夜场的老板,你们究竟在传递怎样的价值观?点开那些视频,评论区里也是呈现明显的两极分化:一种是​​经济下行论​​:“现在就业市场已经艰难到这种程度了吗?”​​一种是事实反驳派​​:这些创作者往往拥有名校背景,从事着...
牛客刘北:被环境教育的,为了能拿到足够的钱养活自己,不甘心也得甘心,现在的短视频传播的思想的确很扭曲,但是很明显,互联网玩上一年你就能全款提A6,但你全心全意不吃不喝工作一年未必能提A6,但是在高考中考出现这个的确很扭曲,在向大家传播“不上学,玩互联网也可以轻松年入百万”,不是人变了,是社会在变
预测一下26届秋招形势
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务