一个关于数组的问题
那个,如何用数组来写这样一个程序。。输入那个史前的年数,是一个时间段,然后,输出这个时间段内所包含的period namePeriod Name Starting Date(millions of years)
Tertiary 65
Cretaceous 136
Jurassic 192
... ...
还要用上For循环。。求解啊各位大神。。。
2012-11-30 00:28
2012-11-30 08:23

2012-11-30 08:33
程序代码:#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cout << "请输入数据组数: ";
while (cin >> n)
{
int *date=new int[n];
string *name=new string[n];
for (int i=0; i<n; i++)
{
cout << "Period Name : ";
cin >> name[i];
cout << "Starting Date: ";
cin >> date[i];
}
cout << "请输入要查询的时间段:";
int temp;
cin >> temp;
for (int j=0; j<n; j++)
{
if(date[j] <= temp)
cout<<name[j]<<endl;
}
cout << "请输入数据组数: (或者ctrl+z结束)";
}
return 0;
}

2012-11-30 09:35
2012-11-30 17:18