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. angular 获取当前值

  2. PCI Simple Communications Controller

    PCI Simple Communications Controller Intel Management Engine Interface (MEI)

  3. MySQL设置快速删除

    SET FOREIGN_KEY_CHECKS=0; DROP DATABASE ... SET FOREIGN_KEY_CHECKS=1;

  4. Asp.Net MVC参考资料

    Every day up!!!!!! 1.无废话MVC入门教程 2.MVC快速入门 3.MVC小牛之路 4.Web API强势入门指南 5.全网最全的mvc汇总 6.MVC5+EF6+Bootstra ...

  5. ubuntu16.04 dpkg强制安装 teamviewer

    dpkg遇到安装有依赖,而依赖的包有无法安装的时候,可以试试强制安装: .90154_amd64.deb 虽然报错,但是安装后还是可以使用. 如果使用: .90154_amd64.deb 提示下面错误 ...

  6. win10 ubuntu双系统安装后无法引导进入ubuntu

    之前按照先装windows后装ubuntu的方式装的系统,都可以引导到ubuntu,无论是将ubuntu挂在到/boot在windows用easy BCD建立ubuntu引导,还是将ubuntu挂在到 ...

  7. No matter how hard it is or no matter how bad it gets, I am going to make it!

    No matter how hard it is or no matter how bad it gets, I am going to make it! He always had a yearni ...

  8. go slice和数组的区别

    1.使用方式 数组和slice长的很像,操作方式也都差不多,并且slice包含了数组的基本的操作方式,如下标.range循环,还有一些如len()则是多种类型共用,所以根据操作根本搞不清数组和切片的区 ...

  9. jquery 判断checkbox是否被选中问题

    1.jquery库2以上 $("#checkbox_check").click(function(){ alert($(this).prop("checked" ...

  10. Centos 安装Mongo DB

    NOSQL在很短的时间里使用人数据高涨,这不仅是它提出的一种新存储思想,更是因为它在对大数据做操作的效率,明显高于关系数据库 工具/原料   接入Internet的一台Centos计算机 下载安装文件 ...