static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
string licenseKeyFormatting(string S, int K)
{
int len=S.length();
int count=;
string res;
for(int i=len-;i>=;i--)
{
char c=toupper(S[i]);
if(c=='-')
continue;
res.push_back(c);
count++;
if(count==K)
{
res.push_back('-');
count=;
}
}
if(res.back()=='-')
res.pop_back();
reverse(res.begin(),res.end());
return res;
}
};

从后往前扫描,问题不大

482. License Key Formatting的更多相关文章

  1. 【leetcode】482. License Key Formatting

    problem 482. License Key Formatting solution1: 倒着处理,注意第一个字符为分隔符的情况要进行删除,注意字符的顺序是否正序. class Solution ...

  2. 482. License Key Formatting - LeetCode

    Question 482. License Key Formatting Solution 思路:字符串转化为char数组,从后遍历,如果是大写字母就转化为小写字母,如果是-就忽略,如果遍历了k个字符 ...

  3. [LeetCode] 482. License Key Formatting 注册码格式化

    You are given a license key represented as a string S which consists only alphanumeric character and ...

  4. 【LeetCode】482. License Key Formatting 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  5. 482 License Key Formatting 注册码格式化

    详见:https://leetcode.com/problems/license-key-formatting/description/ C++: class Solution { public: s ...

  6. LeetCode_482. License Key Formatting

    482. License Key Formatting Easy You are given a license key represented as a string S which consist ...

  7. [LeetCode] License Key Formatting 注册码格式化

    Now you are given a string S, which represents a software license key which we would like to format. ...

  8. [Swift]LeetCode482. 密钥格式化 | License Key Formatting

    You are given a license key represented as a string S which consists only alphanumeric character and ...

  9. LeetCode算法题-License Key Formatting(Java实现)

    这是悦乐书的第241次更新,第254篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第108题(顺位题号是482).您将获得一个表示为字符串S的许可证密钥,该字符串仅包含字 ...

随机推荐

  1. delphi RAD Studio新版本及路线图 及官方网站 官方 版本发布时间

    delphi  RAD Studio Berlin 10.1 主要是FireMonkey 移动开发的改动,VCL确实没有多大变化. http://docwiki.embarcadero.com/RAD ...

  2. jsp 回车代替tab 自动切换text焦点

    方法一keyCode (IE11以后失效) <html> <head> <meta http-equiv="Content-Type" content ...

  3. c++builder Delphi 直接使用剪贴板 Clipboard

    c++builder Delphi 直接使用剪贴板 Clipboard 剪贴板 delphi use  Vcl.Clipbrd procedure TForm27.FormCreate(Sender: ...

  4. Git----分支管理之分支管理策略04

    通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生产一个新的comm ...

  5. vue -本地服务配置

    1.httpd.conf # # This is the main Apache HTTP server configuration file. It contains the # configura ...

  6. Mysql 获取当月和上个月第一天和最后一天的解决方案

    #获取当前日期select curdate(); #获取当月最后一天select last_day(curdate()): #获取本月的第一天select date_add(curdate(),int ...

  7. JAVA 模拟瞬间高并发

    如何模拟一个并发?当时我的回答虽然也可以算是正确的,但自己感觉缺乏实际可以操作的细节,只有一个大概的描述. 当时我的回答是:“线程全部在同一节点wait,然后在某个节点notifyAll.” 面试官: ...

  8. tomcat APR的配置

    Tomcat 可以使用 APR 来提供超强的可伸缩性和性能,更好地集成本地服务器技术. APR(Apache Portable Runtime) 是一个高可移植库,它是 Apache HTTP Ser ...

  9. DirectShow 制作在Unity3D中可以设置进度的视频播放插件

    如果想在Unity3D中去播放视频文件,那么最方便的方法就是使用它自带的MovieTexture. 可以实现简单的视频播放功能. Play Pause Stop. 有也只有这三个功能,  如果你想要一 ...

  10. SVD 实现

    机器学习相关——SVD分解: http://www.cnblogs.com/luchen927/archive/2012/01/19/2321934.html SVD python实现: import ...