# LeetCode - 0806. Number of Lines To Write String ### 題目網址:https://leetcode.com/problems/number-of-lines-to-write-string/ ###### tags: `LeetCode` `Easy` `模擬` ```cpp= /* -LeetCode format- Problem: 806. Number of Lines To Write String Difficulty: Easy by Inversionpeter */ class Solution { public: vector<int> numberOfLines(vector<int>& widths, string s) { int nowLineLength = 0, lines = 1; for (int i = 0; i != s.size(); ++i) { if (nowLineLength + widths[s[i] - 'a'] > 100) nowLineLength = 0, ++lines; nowLineLength += widths[s[i] - 'a']; } return { lines, nowLineLength }; } }; ```