A就是统计猜对的同位同字符的个数 B就是统计统计猜对的不同位同字符的个数

非常简单的题

 class Solution {
public:
string getHint(string secret, string guess) {
int cntA = , cntB = ;
int sn[] = {}, gn[] = {};
for(string::size_type i = ; i < secret.size(); ++i){
if(secret[i] == guess[i]) cntA++;
sn[secret[i]-'']++;
gn[guess[i]-'']++;
}
for(int i = ; i< ; ++i){
cntB += min(sn[i],gn[i]);
}
char s[];
sprintf(s, "%dA%dB",cntA,cntB-cntA);
return string(s);
}
};

Leetcode 299 Bulls and Cows 字符串处理 统计的更多相关文章

  1. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  2. [leetcode]299. Bulls and Cows公牛和母牛

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  3. 【LeetCode】299. Bulls and Cows 解题报告(Python)

    [LeetCode]299. Bulls and Cows 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题 ...

  4. 299. Bulls and Cows - LeetCode

    Question 299. Bulls and Cows Solution 题目大意:有一串隐藏的号码,另一个人会猜一串号码(数目相同),如果号码数字与位置都对了,给一个bull,数字对但位置不对给一 ...

  5. 【一天一道LeetCode】#299. Bulls and Cows

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 You are ...

  6. 299. Bulls and Cows

    题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...

  7. LeetCode(45)-Bulls and Cows

    题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ...

  8. 299 Bulls and Cows 猜数字游戏

    你正在和你的朋友玩猜数字(Bulls and Cows)游戏:你写下一个数字让你的朋友猜.每次他猜测后,你给他一个提示,告诉他有多少位数字和确切位置都猜对了(称为”Bulls“, 公牛),有多少位数字 ...

  9. Java [Leetcode 229]Bulls and Cows

    题目描述: You are playing the following Bulls and Cows game with your friend: You write down a number an ...

随机推荐

  1. SeleniumIDE初级入门

    Selenium  IDE:它是使用Javascript 脚本语言与CS端的DOM对象进行交互,并且为修改测试用例提供了接口.录制功能是它最大的亮点,录制功能可以让测试人员对需要进行测试的功能流程进行 ...

  2. 第三十三章 metrics(1) - graphite搭建 + whisper存储模式 + 高精度向低精度聚合方式 + 集成StatsD + 集成grafana

    组件介绍: carbon:Carbon实际上是一系列守护进程,组成一个Graphite安装的存储后端.这些守护进程用一个名为Twisted的事件驱动网络引擎监听时间序列数据.Twisted框架让Car ...

  3. 动态获取ul,li的数据

    通过一个小例子讲下动态获取li标签的数据,前台页面原有样式: <div class="flone"> <ul class="fltwo"> ...

  4. 在sqlserver存储过程中给in参数传带逗号值的办法,如传'1','2','3'这样的

    最近在一项目修改中,要在存储过程中给in参数传值,语句写的也对,但怎么执行都得不出结果,如果把这语句直接赋值.执行,却能得出结果,很是奇怪,如: 直接执行select schoolname from ...

  5. Delphi inline编译器优化问题

    function Test():Integer; inline; var P:Pointer; begin FreeMem(P); Result := AtomicIncrement(__gr); / ...

  6. CPU的内部架构和工作原理

    一直以来,总以为CPU内部真是如当年学习<计算机组成原理>时书上所介绍的那样,是各种逻辑门器件的组合.当看到纳米技术时就想,真的可以把那些器件做的那么小么?直到看了Intel CPU制作流 ...

  7. [Shell]正则表达式与通配符

    ----------------------------------------------------------------------------------------- 正则表达式与通配符: ...

  8. [转载~笔记]CentOS单独编译安装PHP gd库扩展

    http://www.nowamagic.net/librarys/veda/detail/2610 安装gd前置库: freetype, jpegsrc, libpng 1. freetypewge ...

  9. js时间 字符串相互转化

    js的时间和字符串的转化的讲解是有很多文章的,基本的都是一致的原理.不过曾经碰到过一个比较坑爹的需求,看到网上很少有相关的总结,所以自己简单的记录一下,给后来的同学们点思路. 当时的需求是这样子的,某 ...

  10. web可用性测试

    1.软件质量模型 2.什么是可用性测试 a. 用户体验   Google搜索界面  ipod  iphone b.使用感受   清爽 ,美观,简洁 3. 一位局长使用B/S系统 今天我点名买了个B/S ...