简体   繁体   English

将字符串拆分为不同的数组

[英]splitting a string into different arrays

My input format the number of types of items, followed by N (N - no.of items) lines each representing a pair of integers in the format LB where L is the length of the item and B is the breadth of the item. 我的输入会格式化项目的类型数,然后是N(N-项目数)行,每行代表LB格式的一对整数,其中L是项目的长度,B是项目的宽度。

Sample input format: 样本输入格式:
2 2
1 1 1 1
5 4 5 4

My question is how send all lengths into one array and all breadths into one array with out using vectors in C++. 我的问题是如何在不使用C ++中的向量的情况下将所有长度发送到一个数组,将所有宽度发送到一个数组。 I know these kind of questions were already asked by people but I couldn't figure out how to send them to two different arrays. 我知道人们已经问过这类问题,但我不知道如何将它们发送到两个不同的数组。

my program should run in a sandbox. 我的程序应该在沙箱中运行。 Sandbox automatically gives input to the program. 沙盒会自动为程序提供输入。 So I have to write my program in a way that takes the above input format 所以我必须采用上述输入格式来编写程序

cin >> n;
int *l,*b;
l = new int[n];
b = new int[n];

for(int i=0; i<n; ++i) {
  cin >> l[i] >> b[i];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM