Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1019一道水题

Posted by a3505835 at 2012-03-13 10:51:18
对vector不太熟悉,就拿1019练练手。发现输入小点的数据还可以,但大了就会有out of the
range。请各位看看问题出在哪里:

#include <iostream>
#include <vector>
using namespace std;

class Sequence
{
public:
  vector <int>v;
 void  ge(int i);
};
void Sequence::ge(int i) //将数据分割成单个数字,push入v栈中,
{
	int n=0;
	int arr[5];
	while(i)
	{
	 arr[n]=i%10;
	 i=i/10;
	 n++;
         }
	for(n=n-1;n>=0;n--)
	  v.push_back(arr[n]);
 }
int main()

 { 
	int n;
	cin>>n;
	while(n)
	 {  
		long int i;
		Sequence obj;
	    int j;
		 cin>>i;
        for(j=1;j<1005;j++)
		{
			obj.ge(j);
			if(i<=obj.v.size())
				 break;
			i=i-obj.v.size();
		}
		if(i==obj.v.size())
			cout<<*(obj.v.end()-1)<<endl;
		else 
			cout<<*(obj.v.begin()+i-1)<<endl;
		 
	  n--;
	} 
  return 0;
 }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator