码迷,mamicode.com
首页 > 其他好文 > 详细

806. Number of Lines To Write String

时间:2018-06-14 14:54:13      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:vector   class   stat   int   line   syn   solution   ati   lines   

 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio(false);
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     vector<int> numberOfLines(vector<int>& widths, string S) 
12     {
13         int count=1,length=0;
14         for(char c:S)
15         {
16             int cur=widths[c-a];
17             if(cur+length<100)
18             {
19                 length+=cur;
20                 continue;
21             }
22             else if(cur+length==100)
23             {
24                 count++;
25                 length=0;
26             }
27             else
28             {
29                 count++;
30                 length=cur;
31             }
32         }
33         return {count,length};
34     }
35 };

直接扫描,统计长度就行,问题不大

806. Number of Lines To Write String

标签:vector   class   stat   int   line   syn   solution   ati   lines   

原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9182132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!