64,651
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char**argv)
{
int data[40];
char input[BUFSIZ];
int i,j;
char*tp;
fgets(input,BUFSIZ,stdin);
i=0;
tp=strtok(input," ");
while(tp!=NULL)
{
data[i++]=atoi(tp);
tp=strtok(NULL," ");
}
printf("arr:");
for(j=0;j<i;j++)
printf("%d ",data[j]);
printf("\n");
}
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iterator>
using namespace std;
int str2int(string str)
{
int n;
istringstream is(str);
is>>n;
return n;
}
int main()
{
vector<int> arr;
string line;
getline(cin,line);
stringstream ss(line);
string subs;
while(getline(ss,subs,' '))
{
int n=str2int(subs);
arr.push_back(n);
}
// cout<<"ok"<<endl;
copy(arr.begin(),arr.end(),ostream_iterator<int>(cout," "));
cout<<endl;
}
#include<iostream>
using namespace std;
int main() {
int num=0;
int *series=NULL;//the elements are integers
cout<<"please input the number of elements: ";
cin>>num;
series=new int[num];
cout<<"please input the elements one by one: ";
for(int i=0; i<num; ++i) {
cin>>series[i];//seperated by space
}
for(int i=0; i<num; ++i) {
cout<<series[i]<<ends;
}
delete series;
series=NULL;
return 0;
}
#include <stdio.h>
int main() {
int num=0;
int *series=NULL;//the elements are integers
printf("please input the number of elements: ");
scanf("%d", &num);
series=(int*) malloc(num);
printf("please input the elements one by one: ");
for(int i=0; i<num; ++i) {
scanf("%d", &series[i]);//seperated by enter
}
for(int i=0; i<num; ++i) {
printf("%d ", series[i]);
}
free(series);
return 0;
}
#include<iostream>
using namespace std;
int main(){
int a[100],n;
while(cin>>n){
for(int i=0;i<n;i++)
cin>>a[i];
}
return 0;
}