Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <string>
- #include <iterator>
- #include <algorithm>
- using namespace std;
- void trim(string &str) {
- string::iterator b = str.begin();
- while (isspace(*b)) {
- b++;
- }
- string::iterator e = str.end();
- while (isspace(*(e - 1))) {
- e--;
- }
- str.assign(b, e);
- }
- int main()
- {
- char str[200];
- cin.getline(str, 200);
- char *pch = strtok (str, " "), *word = 0;
- int length = strlen(pch);
- int maxLen = 0;
- string ss = string(str);
- trim(ss);
- strcpy(str, ss.c_str() );
- while (pch != NULL)
- {
- length = strlen(pch);
- if (maxLen < length)
- {
- maxLen = length;
- word = pch;
- }
- pch = strtok (NULL, " ");
- }
- cout << word << endl;
- cout << maxLen;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement