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. hdu 3661 Assignments (贪心)

    Assignments Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. MVC 学习(二)之Linq to Sql 简单Demo

    Linq to Entities 已经我的一篇博文中阐述了,这里阐述一下简单的Linq to Sql 的增删改查.Linq to sql 与Linq to Entities虽然同属于DataBase- ...

  3. TFS2010安装办法及序列号

    安装过程: 一.安装操纵体系 安装Windows 2008 R2简体中文版 二.筹办安装过程中的须要的用户账户,并设置响应权限 具体流程如下: 1.点击“开端”——“经管对象”——“计较机经管” 2. ...

  4. 問題排查:行動裝置網頁前端 UI 設計 (1)

    這是最近開始接手的一個微信公眾平台專案, 在重整後端程式碼時,因為也需要透過前端來看效果, 所以就因此在前端的部分遇到了不少問題, 畢竟這是以前沒接觸過的領域 (早年的網頁應用程式開發沒有那麼多分工) ...

  5. IOS一些好的用户体验设置

    1,下载图片时,如果 用户操作UI,那么就停止子线程,用户停止操作子线程时,开启子线程继续下载. SDWebImage  :专门下载图片. 2,网络请求时.本地要进行一些验证,以减少服务器的压力.

  6. 如何在命令行里运行python脚本

    python是一款应用非常广泛的脚本程序语言,谷歌公司的网页就是用python编写.python在生物信息.统计.网页制作.计算等多个领域都体现出了强大的功能.python和其他脚本语言如java.R ...

  7. css3之转换

    1.2D转换 2.3D转换 transform-style属性(设置三维/二维效果) 值: flat表示子元素不保留3D设置(默认) preserve-3d表示子元素保留3D设置 transform属 ...

  8. GDI+技术

    GDI+是GDI的后继者,它是一种构成 Windows XP 操作系统的子系统的应用程序编程接口. 一般来说有3种基本类型的绘图界面,分别为Windows 窗体上的控件.要发送给打印机的页面和内存中的 ...

  9. 非官方windows下Cpython二进制扩展包下载地址

    Unofficial Windows Binaries for Python Extension Packages url:http://www.lfd.uci.edu/~gohlke/pythonl ...

  10. linux中实现自动交互的3中方法

    本文参考了 http://os.51cto.com/art/200912/167898.htm 有些命令例如ftp需要交互,有三种方法可以实现. 方法一(重定向)简单直观,也经常有实际应用,但是在自动 ...