Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[591] Re: STL을 사용한 방법
김백일 [cedar] 1702 읽음    2002-05-09 00:23
: 1+(1+2)+(1+2+3)+ ............ +(1+2+3+4+......+19+20) 의 합을 구하시오..

STL을 써서, for 루프를 쓰지 않고 구현하는 방법입니다.

// Illustrating the generic partial_sum algorithm
#include <iostream>
#pragma hdrstop
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>

using namespace std;

int main()
{
  cout << "Illustrating the generic iota and partial_sum algorithm."
       << endl;
  const int N = 20;
  vector<int> x1(N), x2(N);

  // ANSI C++ 표준에는 없습니다: 빌더 5이하에서는 STLport를 설치하세요.
  iota(x1.begin(), x1.end(), 1);
 
  copy(x1.begin(), x1.end(), ostream_iterator<int>(cout, " "));
  cout << endl;

  // Compute the partial sums of 1, 2, 3, ..., N
  // putting the result in x2:
  partial_sum(x1.begin(), x1.end(), x2.begin());

  copy(x2.begin(), x2.end(), ostream_iterator<int>(cout, " "));
  cout << endl;

  return 0;
}


+ -

관련 글 리스트
585 [질문]기본적인거같은데.. 잘 안되네여... Danke.. 1699 2002/05/08
591     Re: STL을 사용한 방법 김백일 1702 2002/05/09
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.