Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 3) Кол-во слов и самое длинное
- */
- #include <iostream>
- using namespace std;
- int main()
- {
- const int N = 100000;
- char S[N];
- cin.getline(S, N);
- int z;
- int max = 0, t = 0, kol = 0;
- for (int i = 0; S[i]; i++)
- {
- if (S[i] != ' ' && S[i + 1] == ' ' || S[i] != ' ' && S[i + 1] == '\0')
- {
- kol++;
- }
- if (S[i] != ' ')
- {
- t++;
- if (t > max)
- {
- max = t;
- z = i;
- }
- }
- else
- {
- t = 0;
- }
- }
- cout << "kol: " << kol << endl;
- for (int i = z - max + 1; i < z + 1; i++)
- {
- cout << S[i];
- }
- }
Add Comment
Please, Sign In to add comment