Олимпиада по информатике

Similar documents
STL Standard Template Library

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Bruce Merry. IOI Training Dec 2013

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming

CS197c: Programming in C++

Lab 1: First Steps in C++ - Eclipse

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

CSI33 Data Structures

Streams. Ali Malik

What will happen if we try to compile, link and run this program? Do you have any comments to the code?

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Type Aliases. Examples: using newtype = existingtype; // C++11 typedef existingtype newtype; // equivalent, still works

CPSC 427a: Object-Oriented Programming

19.1 The Standard Template Library

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Suppose that you want to use two libraries with a bunch of useful classes and functions, but some names collide:

STL Containers. Porter Scobey Also,

Advanced Associative Containers. Ali Malik

Lecture 3 The character, string data Types Files

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library

Linked List using a Sentinel

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

Templates and Vectors

Perfect square. #include<iostream> using namespace std; int main(){ int a=1; int square; while(true){ } cout<<square<<endl; }

The Standard Template Library. EECS 211 Winter 2018

Exercise 1.1 Hello world

Lectures 11,12. Online documentation & links

Module 9. Templates & STL

CSCI-1200 Computer Science II Fall 2008 Lecture 15 Associative Containers (Maps), Part 2

CSE100. Advanced Data Structures. Lecture 4. (Based on Paul Kube course materials)

COMP322 - Introduction to C++

Computer Science II Lecture 2 Strings, Vectors and Recursion

1. The term STL stands for?

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Lecture on pointers, references, and arrays and vectors

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Function Templates. Consider the following function:

Intermediate Programming, Spring 2017*

EL2310 Scientific Programming

struct Buffer { Buffer(int s) { buf = new char[s]; } ~Buffer() { delete [] buf; } char *buf; };

CS302 - Data Structures using C++

Programming with Haiku

Exercise 6.2 A generic container class

CSCE 206: Structured Programming in C++

C++ Namespaces, Exceptions

Increment and the While. Class 15

CS

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

CS 376b Computer Vision

Programming C++ Lecture 2. Howest, Fall 2014 Instructor: Dr. Jennifer B. Sartor

Lambda functions. Zoltán Porkoláb: C++11/14 1

Containers in C++ and Java

DataStruct 9. Hash Tables, Maps, Skip Lists, and Dictionaries

Working with Batches of Data

General Advise: Don t reinvent the wheel

Review Questions for Final Exam

Computational Physics

Engineering Problem Solving with C++, Etter

C++14 Reflections Without Macros, Markup nor External Tooling

Lecture 5 Files and Streams

vector<int> second (4,100); // four ints with value 100 vector<int> third (second.begin(),second.end()); // iterating through second

TEMPLATES AND ITERATORS

CSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

Lecture 12. Monday, February 7 CS 215 Fundamentals of Programming II - Lecture 12 1

Informatik I (D-ITET) Übungsstunde 9, Hossein Shafagh

Unified Modeling Language a case study

Today. andyoucanalsoconsultchapters6amd7inthetextbook. cis15-fall2007-parsons-lectvii.1 2

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

Object Reference and Memory Allocation. Questions:

Functions. Ali Malik

COM S 213 PRELIM EXAMINATION #2 April 26, 2001

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

W3101: Programming Languages C++ Ramana Isukapalli

SDV4001 Object Oriented Programming with C++ and UI Midterm 2013

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Text File I/O. #include <iostream> #include <fstream> using namespace std; int main() {

Integer Data Types. Data Type. Data Types. int, short int, long int

Lecture 4a Using The Standard Template Library. Jack Applin, Guest Lecturer

int main() { int account = 100; // Pretend we have $100 in our account int withdrawal;

Introduction to C++ Day 2

CSCI-1200 Data Structures Fall 2016 Lecture 17 Associative Containers (Maps), Part 2

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

STL: C++ Standard Library

C++17 and Beyond. Mark Isaacson

Fundamentals of Programming CS-110. Lecture 2

C++: Overview and Features

Exceptions, Case Study-Exception handling in C++.

CSE 100: C++ TEMPLATES AND ITERATORS

Lecture 8. Xiaoguang Wang. February 13th, 2014 STAT 598W. (STAT 598W) Lecture 8 1 / 47

The Standard Template Library. An introduction

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.

Outline. 1 About the course

CSE 333 Final Exam June 6, 2017 Sample Solution

the Stack stack ADT using the STL stack are parentheses balanced? algorithm uses a stack adapting the STL vector class adapting the STL list class

STL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms

Examination C++ Programming

Lectures 19, 20, 21. two valid iterators in [first, last) such that i precedes j, then *j is not less than *i.

Introduction to C ++

Reference operator (&)

Transcription:

Олимпиада по информатике Синица Сергей Геннадьевич Председатель региональной предметно-методической комиссии Доцент кафедры информационных технологий КубГУ

Язык программирования С++ или Java + Стандартная библиотека структур данных и алгоритмов + Документация доступна онлайн + Удобные современные инструменты разработки и отладки + Возможность работы с компиляторами, используемыми при автоматизированной проверке Яндекс.Контест

Компилятор и IDE для С++ GCC и CodeBlocks или Eclipse + Кроссплатформенные + Быстро работают + Компилятор GCC как в Яндекс.Контест

CodeBlocks + GCC Debian/Ubuntu Linux sudo apt-get install build-essential sudo apt-get install codeblocks Windows 1) http://codeblocks.org 2) Downloads 3) Binary release 4) codeblocks-17.12mingw-nosetup.zip

CodeBlocks + GCC

С++ 11, третье+ издание

Hello World! #include <bits/stdc++.h> using namespace std; int main() { cout << "Hello world!" << endl; return 0;

IO #include <bits/stdc++.h> using namespace std; int main() { std::ifstream infile("task1.in"); int a, b; infile >> a; infile >> b; std::ofstream outfile("task1.out"); outfile << (a+b); return 0;

STL pair #include <bits/stdc++.h> using namespace std; int main() { pair <string, double> product1; pair <string, double> product2("помидоры", 2.30); pair <string, double> product3(product2); product1 = make_pair(string("лампочки"), 0.99); product2.first = "Обувь"; product2.second = 39.90; cout << "Цена " << product1.first << " В $" << product1.second << '\n'; cout << "Цена " << product2.first << " В $" << product2.second << '\n'; cout << "Цена " << product3.first << " В $" << product3.second << '\n'; return 0;

STL touple #include <bits/stdc++.h> using namespace std; int main () { tuple<int,char> foo (10,'x'); auto bar = make_tuple ("test", 3.1, 14, 'y'); get<2>(bar) = 100; int myint; char mychar; tie (myint, mychar) = foo; tie (ignore, ignore, myint, mychar) = bar; mychar = get<3>(bar); get<0>(foo) = get<2>(bar); get<1>(foo) = mychar; cout << "foo contains: "; cout << get<0>(foo) << ' '; cout << get<1>(foo) << '\n'; return 0;

STL vector #include <bits/stdc++.h> using namespace std; int main () { vector<int> first; vector<int> second (4,100); vector<int> third (second.begin(),second.end()); vector<int> fourth (third); cout << second[1]; // the iterator constructor can also be used to construct from arrays: int myints[] = {16,2,77,29; vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) ); cout << "The contents of fifth are:"; for (vector<int>::iterator it = fifth.begin(); it!= fifth.end(); ++it) cout << ' ' << *it; cout << '\n'; return 0;

STL unordered_map #include <bits/stdc++.h> using namespace std; int main () { unordered_map<string,double> mymap = { {"mom",5.4, {"dad",6.1, {"bro",5.9 ; string input; cout << "who? "; getline (cin,input); unordered_map<string,double>::const_iterator got = mymap.find (input); if ( got == mymap.end() ) cout << "not found"; else cout << got->first << " is " << got->second; cout << std::endl; return 0;

STL multimap #include <bits/stdc++.h> using namespace std; int main() { multimap<char, int>mymm; mymm.insert(make_pair('x', 10)); mymm.insert(make_pair('y', 20)); mymm.insert(make_pair('z', 30)); mymm.insert(make_pair('z', 40)); multimap<char, int>::iterator it = mymm.find('x'); mymm.erase(it); mymm.erase(mymm.find('z')); cout << "elements in mymm:" << '\n'; cout << "y=>" << mymm.find('y') -> second << '\n'; cout << "z=>" << mymm.find('z') -> second << '\n'; return 0;

STL bitset #include <bits/stdc++.h> using namespace std; int main () { bitset<5> foo (string("01011")); cout << "foo contains:\n"; cout << std::boolalpha; for (size_t i=0; i<foo.size(); ++i) cout << foo.test(i) << '\n'; return 0;

STL algorithms: sort, N * log(n) #include <bits/stdc++.h> using namespace std; int main() { vector<int> intvec = {56, 32, -43, 23, 12, 93, 132, -154; vector<string> stringvec = {"Сергей", "Катя", "Алексей", "Лена"; // sort using the default operator < sort(intvec.begin(), intvec.end()); for (vector<int>::size_type i = 0; i!= intvec.size(); ++i) cout << intvec[i] << " "; cout << endl; sort(stringvec.begin(), stringvec.end()); for (auto s : stringvec) cout << s << " "; // sort using a standard library compare function object sort(stringvec.begin(), stringvec.end(), greater<string>()); for (auto a : stringvec) { cout << a << " "; cout << endl;

STL algorithms: sort, N * log(n) // sort using a custom function object struct { bool operator()(int a, int b) const { return a < b; customless; sort(intvec.begin(), intvec.end(), customless); for (auto a : intvec) { cout << a << " "; cout << '\n'; // sort using a lambda expression sort(intvec.begin(), intvec.end(), [](int a, int b) { return a > b; ); for (auto a : intvec) { cout << a << " "; cout << '\n'; return 0;

STL binary search #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { vector<int> haystack {1, 3, 4, 5, 9; vector<int> needles {1, 2, 3; for (auto needle : needles) { cout << "Searching for " << needle << '\n'; if (binary_search(haystack.begin(), haystack.end(), needle)) { cout << "Found " << needle << '\n'; else { cout << "no dice!\n";

Алгоритмы http://ru.cppreference.com/w/cpp/algorithm

Задачи http://codeforces.com/problemset