滴滴笔试,谁能告诉我,不能输入数组长度,你们咋做的啊

编程题卡在了第一步,表示很尴尬

#滴滴#
全部评论
vector<int> number; int temp_num; do { cin>>temp_num; number.push_back(temp_num); }while(getchar()!='\n');
点赞 回复 分享
发布于 2017-08-26 17:32
#include<iostream> #include<vector> using namespace std; int main() { vector<int> a; int tmp,n=0; do { cin>>tmp; n++; a.push_back(tmp); }while(getchar()!='\n'); for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; return 0; }
点赞 回复 分享
发布于 2017-08-26 18:12
int arr[100000] = {0}; int arr_count = 0; while (scanf("%d",&arr[arr_count]) != EOF && getchar() != '\n')     arr_count++;
点赞 回复 分享
发布于 2017-08-26 17:48
while(cin>>k) ivec.push_back(k); ivec.pop_back();//k就是第几大的k
点赞 回复 分享
发布于 2017-08-26 17:31
https://www.nowcoder.com/courses/7            牛客网OJ视频
点赞 回复 分享
发布于 2017-08-26 22:00
vector<int> v; char c; int t; cin>>t; v.push_back(t); while((c=getchar())!='\n'){ cin>>t; v.push_back(t); }
点赞 回复 分享
发布于 2017-08-26 20:59
#include<iostream> #include<sstream> #include<string> using namespace std; int main() { string line; getline(cin, line); stringstream ss(line); int tmp=0; int a[999],n=0; while (ss >> tmp) { a[n]=tmp; n++; } for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; return 0; }
点赞 回复 分享
发布于 2017-08-26 17:55
//我的菜鸡操作 String input = scanner.nextLine(); String[] a = input.split(" "); int[] b = new int[a.length]; for(int i = 0; i < a.length; i ++){ String aString = a[i]; b[i] = Integer.parseInt(aString); }
点赞 回复 分享
发布于 2017-08-26 17:48
int temp=0; while(scanf("%d",&temp)!=EOF){ }
点赞 回复 分享
发布于 2017-08-26 17:24
string line; cin.getline(cin, line); stringstream ss(line); int tmp = 0; while (ss >> tmp) { // deal with tmp }
点赞 回复 分享
发布于 2017-08-26 17:23
Scanner sin = new Scanner(System.in); String line = sin.readLine(); String[] strs = line.split(" "); int n = strs.length;
点赞 回复 分享
发布于 2017-08-27 09:48
#include <iostream> #include <algorithm> #include <vector> using namespace std; bool comp(const int &a, const int &b) { return a > b; } int main() { int temp; vector<int> vec; do { cin >> temp; vec.push_back(temp); } while (getchar() != '\n'); int k; cin >> k; sort(vec.begin(), vec.end(), comp); cout << vec[k - 1] << endl; system("pause"); return 0; }
点赞 回复 分享
发布于 2017-08-27 00:27
Scanner in = new Scanner(System.in); String[] input = in.nextLine().split(" "); int[] b = new int[input.length]; for(int i=0;i<input.length;i++){ b[i] = Integer.parseInt(input[i]); }
点赞 回复 分享
发布于 2017-08-26 22:17
各位大神,想问一下,next(),nextInt(),nextLine()的区别啊,例如  2 3 4 5 6 2 这样的输入用next()是不是只能读完第一行,第2行就读不了了
点赞 回复 分享
发布于 2017-08-26 21:50
     Scanner scanner = new Scanner(System.in); ArrayList<Integer> list = new ArrayList<>(); while(scanner.hasNextInt()){ list.add(scanner.nextInt()); } int len = list.size(); int arr[] = new int[len-1]; int k = list.get(len-1); for(int i=0;i<len-1;i++){ arr[i] = list.get(i); } Arrays.sort(arr); System.out.println(arr[arr.length-k]);
点赞 回复 分享
发布于 2017-08-26 20:35
l=list(map(int,input().split())) n=int(input()) l.sort(reverse = True) print(l[n-1])
点赞 回复 分享
发布于 2017-08-26 19:52
python的是 nums=[int(i) for i in raw_input().split(" ")]
点赞 回复 分享
发布于 2017-08-26 18:34
vector<int> sourceVec; int  temp; char t; while ((cin >> temp).get(t)) {        sourceVec.push_back(temp);         if (t == '\n')                break; }
点赞 回复 分享
发布于 2017-08-26 18:29
#coding = utf-8 import sys if __name__ == "__main__": num = sys.stdin.readline().strip().split(' ') lst = [] for i in num: lst.append(int(i)) left = res = -10000000000 for i in lst: left = max(i,left+i) res = max(left,res) print res Python就这样即可
点赞 回复 分享
发布于 2017-08-26 18:22
第一个有负号的,大佬们都怎么做的,我用的char和str,不断判断char的类型,没想到什么好方法
点赞 回复 分享
发布于 2017-08-26 17:49

相关推荐

评论
点赞
收藏
分享

创作者周榜

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