forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargestWordInSentence.cpp
More file actions
50 lines (38 loc) · 809 Bytes
/
largestWordInSentence.cpp
File metadata and controls
50 lines (38 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin>>n;
cin.ignore();
char arr[n+1];
cin.getline(arr, n);
cin.ignore();
int i=0;
int currLen =0, maxLen=0;
int st=0, maxst=0;
while(1){
if(arr[i] == ' ' || arr[i] == '\0'){
if(currLen>maxLen){
maxLen = currLen;
maxst = st;
}
currLen = 0;
st = i+1;
}
else
currLen++;
if(arr[i] == '\0'){
break;
}
i++;
}
cout<<maxLen<<endl;
for(int i=0;i<maxLen;i++){
cout<<arr[i+maxst]<<" ";
}
return 0;
}