BearCheats

Problem Statement
    
Limak is an old brown bear. Because of his bad eyesight he sometimes has to visit his doctor, Dr. Carrot. Today is one such day.

Dr. Carrot has a blackboard in his office. There is a number A written on the blackboard. In order to examine Limak's eyesight, Dr. Carrot asked him to read the number. Limak couldn't see the number really well. He could determine the number of digits correctly, but he was not sure what the individual digits are. Finally, he decided to announce the number B to the doctor. The doctor then left the office for a short while.

Limak really doesn't want to wear glasses, so he has decided to cheat. As soon as the doctor left the room, Limak went to the blackboard to read the correct number A. Before the doctor returns, Limak has the time to change one of the digits of A to any different digit. (Note that he may not add any new digits to A and he may not completely erase any digits of A. He may only change at most one of the digits.) Limak hopes that he can deceive the doctor by changing the number A into his number B.

You are given the ints A and B. Return the string "happy" (quotes for clarity) if Limak can convince the doctor that his eyesight is good. Otherwise, return the string "glasses".
Definition
Class:BearCheats
Method:eyesight
Parameters:int, int
Returns:string
Method signature:string eyesight(int A, int B)(be sure your method is public)
Limits
Time limit (s):2.000
Memory limit (MB):256
Stack limit (MB):256
Constraints
A and B will be between 1 and 999,999, inclusive.
A and B will have the same number of digits.
Examples
0)

8072
3072
Returns: "happy"
Limak wants to change 8072 into 3072. He can do that by changing the digit 8 to a 3.
1)

508
540
Returns: "glasses"
Limak would need to change two digits, but he only has the time to change at most one.
2)

854000
854000
Returns: "happy"
It is possible that Limak read the number correctly. If that happens, he will not change any digits.
3)

1
6
Returns: "happy"

4)

385900
123000
Returns: "glasses"

题意:

一个人去配眼镜,但是他不想戴眼镜,于是他就作弊,可以改变一位数字,然后问你能不能改对

题解:

int转成string后,看长度是否一样,然后再看有多少个不一样

代码:

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std; class BearCheats{
public:
string eyesight(int A, int B){
char t[];
string s1;
sprintf(t, "%d", A);
s1 = t;
string s2;
char t2[];
sprintf(t2,"%d",B);
s2 = t2;
if(s1.size()!=s2.size())
return "glasses";
int flag=;
for(int i=;i<s1.size();i++)
if(s1[i]!=s2[i])
flag++;
if(flag>)
return "glasses";
return "happy";
}
};

TC SRM 664 div2 A BearCheats 暴力的更多相关文章

  1. TC SRM 663 div2 A ChessFloor 暴力

    ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...

  2. TC SRM 665 DIV2 A LuckyXor 暴力

    LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...

  3. TC SRM 665 DIV2 B LuckyCycle 暴力

    LuckyCycleTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...

  4. TC SRM 664 div2 B BearPlaysDiv2 bfs

    BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by ...

  5. topcpder SRM 664 div2 A,B,C BearCheats , BearPlays equalPiles , BearSorts (映射)

    A题,熊孩子测视力,水题,题意就是判断一下两个数对应位不相同的数字有多少个. #include<bits/stdc++.h> using namespace std; class Bear ...

  6. TC SRM 663 div2 B AABB 逆推

    AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...

  7. TC SRM 607 DIV2

    求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了. 复习了一下求最长子回文串的算法,发现可以类似解决. 给相邻字符之间添加一个'@'字符,这样所有的回文串都是奇数长 ...

  8. TC SRM 593 DIV2 1000

    很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...

  9. TC SRM 591 DIV2 1000

    很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...

随机推荐

  1. NYOJ-779-兰州烧饼

    [题目链接:NYOJ-779] 兰州烧饼 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 烧饼有两面,要做好一个兰州烧饼,要两面都弄热.当然,一次只能弄一个的话,效率 ...

  2. binlog/relay_log的清理

    http://www.yuminstall.com/how-to-remove-mysql-relay-log.html CHANGE MASTER TO changes the parameters ...

  3. [Everyday Mathematics]20150204

    设 $k_0>0$, $\phi:[k_0,\infty)\to[0,\infty)$ 是有界递减函数, 并且 $$\bex \phi(k)\leq \frac{A}{(k-h)^\al}\ph ...

  4. 2016计蒜之道复赛 百度地图的实时路况 floyd+cdq分治

    链接:https://nanti.jisuanke.com/t/11217 奉上官方题解: 枚举 d(x , y , z) 中的 y,把 y 从这个图中删去,再求这时的全源最短路即可,使用 Floyd ...

  5. Linux基本命令(2)有关磁盘空间的命令

    有关磁盘空间的命令 命令 功能 mount 挂载文件系统 umount 卸载已挂载上的文件系统 df 检查各个硬盘分区和已挂上来的文件系统的磁盘空间 du 显示文件目录和大小 fsck 主要是检查和修 ...

  6. JDBC连接工厂类

       看到有些书上数据库连接提供两个工厂类,一个连接工厂类一个关闭工厂类,并且关闭工厂类写了多种重载形式,感觉没有必要,这样写比较简洁一些. /** * 抽象出的连接工厂类,提供连接数据库和关闭连接的 ...

  7. C#条件语句、循环语句

    一.程序的三种结构 顺序结构 分支结构 循环结构 二.条件语句if 语句是最有用的控制结构之一. if … else …语句的语法: if (布尔表达式)执行操作的语句  或if (布尔表达式)执行操 ...

  8. JavaScript中的事件冒泡机制

    事件冒泡机制 事件冒泡发生的条件:当为多个嵌套的元素设置了相同的事件处理程序,它们将触发事件冒泡机制.在事件冒泡中,最内部的元素将首先触发其事件,然后是栈内的下一个元素触发该事件,以此类推,直到到达最 ...

  9. Codeforces Round #361 (Div. 2)

    A 脑筋急转弯 // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream&g ...

  10. android判断当前网络状态及跳转到设置界面

    今天,想做这个跳转到网络设置界面, 刚开始用 intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); 不料老是出现settings.Wirele ...