class Solution {
public:
/**
* @param sentence: a list of string
* @param rows: an integer
* @param cols: an integer
* @return: return an integer, denote times the given sentence can be fitted on the screen
*/
int wordsTyping(vector<string> &sentence, int rows, int cols) {
// Write your code here
int m=1,n=0,i;
for(i=1;m<=rows;i++){
for(int j=0;j<sentence.size();j++){
if(n+sentence[j].size()+1<=cols) n+=sentence[j].size()+1;
else {
m++;
n=sentence[j].size();
}
}
}
return i-2;
}
};