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

Re:vector遍历器很不错,小试一下,0ms过

Posted by bhq at 2009-08-01 02:56:40 on Problem 1552 and last updated at 2009-08-01 02:57:35
In Reply To:做题有感ps Posted by:niuniu2006 at 2007-06-19 20:46:24
//先对输入的数列排序,找出其中偶数组成一列,再将输入的数列中的数逐个与偶数列中的数对比

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

int main()
{
	vector<int> evenNum , inputNum;
	int temp , num;
	while ( cin >> temp && temp + 1 )
	{
		num = 0;
		inputNum.push_back(temp);
		while ( cin >> temp && temp )
		{
			inputNum.push_back(temp);
		}
		sort(inputNum.begin(),inputNum.end());
		for ( vector<int>::iterator it = inputNum.begin() ; it != inputNum.end() ; ++ it )
		{
			if ( *it % 2 == 0 )
			{
				evenNum.push_back(*it);
			}
		}
		for ( vector<int>::iterator it1 = inputNum.begin() , it2 = evenNum.begin() ; it1 != inputNum.end() && it2 != evenNum.end() ; )
		{
			if ( *it1 * 2 < *it2 )
			{
				++ it1;
				continue;
			}
			if ( *it1 * 2 == *it2 )
			{
				++ num;
				++ it1;
				++ it2;
				continue;
			}
			if ( *it1 * 2 > *it2 )
			{
				++ it2;
			}
		}
		cout << num << endl;
		evenNum.clear();
		inputNum.clear();
	}
	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