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. Oracle SQL*plus常用的命令和函数

    常用命令: 连接sqlplus命令行下运行cmd进入,如以sys模式登陆,命令如下:(1).sqlplus "sys/zhb126 as sysdba" (2).sqlplus/n ...

  2. java核心知识点学习----重点学习线程池ThreadPool

    线程池是多线程学习中需要重点掌握的. 系统启动一个新线程的成本是比较高的,因为它涉及与操作系统交互.在这种情形下,使用线程池可以很好的提高性能,尤其是当程序中需要创建大量生存期很短暂的线程时,更应该考 ...

  3. sublime text保存时删除行尾空格

    打开sublime text,点击在Preferences, Settings-User打开的用户配置中加入以下一行: "trim_trailing_white_space_on_save& ...

  4. Spring IOC容器中注入bean

    一.基于schema格式的注入 1.基本的注入方式 (属性注入方式) 根据setXxx()方法进行依赖注入,Spring只会检查是否有setter方法,是否有对应的属性不做要求 <bean id ...

  5. Android Log介绍

    android.util.Log常用的方法有以下5个:Log.v() ,Log.d() ,Log.i() ,Log.w() ,Log.e() .按照日志级别从高到低为ERROR, WARN, INFO ...

  6. 关于php中正则匹配包括换行符在内的任意字符的问题总结

    要使用正则匹配任意字符的话,通常有以下几种方法,这里我分别对每一种方法在使用的过程中做一个总结: 第一种方式:[.\n]*? 示例 ? PHP preg_match_all('/<div cla ...

  7. JS 获取服务器时间

    function getSevertime(){ var xmlHttp = new XMLHttpRequest(); xmlHttp.open("get",location.h ...

  8. StringGrid 实例5 本例功能:字体修改为居中,红色,20号

    实例5 本例功能: 在FireMonkey中StringGrid对于字体的调整由于没有font属性和onDrawCell事件使得变得有些麻烦,后来费了一些功夫才找到方法.但由于XE3中某些属性还是没有 ...

  9. Java 第11章 类的无参方法

    类的无参方法 类的方法由哪几部分组成? 方法的定义: 1.访问权限修饰符 2.方法返回的数据类型 3.方法的名称 4.方法的主体 成员变量和局部变量的区别有那些? ~ 作用域不同 - 成员变量的作用域 ...

  10. <转载> OpenGL Projection Matrix

    原文 OpenGL Projection Matrix Related Topics: OpenGL Transformation Overview Perspective Projection Or ...