Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:vector遍历器很不错,小试一下,0ms过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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator