Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Napisz funkcję Najdluzsze, która zwraca indeks najdłuższego słowa wśród pierwszych n słów tekstu. Słowa są przechowywane w wektorze A. Prototyp funkcji ma postać:
- int Najdluzsze(const vector<string> & A, int n);
- Co trzeba założyć o klasie vector i o klasie string, aby zadanie to wykonać w łatwy sposób? (Jakie metody z tych klas są potrzebne?)
- Napisz program testujący opracowaną funkcję.
- */
- #include "stdafx.h"
- #include <queue>
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <stack>
- using namespace std;
- int Najdluzsze(const vector<string> & A, int n){
- int indexMax = 0;
- for(int i = 0; i < n; i++){
- if(sizeof(A[i]) > indexMax) indexMax = i;
- }
- return indexMax;
- }
- int _tmain(int argc, _TCHAR* argv[]){
- vector <string> A(5);
- A[0] = "ala";
- A[1] = "ma";
- A[2] = "kota";
- A[3] = "i";
- A[4] = "pterodaktyla";
- int max = Najdluzsze(A,5);
- cout << max << endl;
- system ("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment