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. 【MySQL】Java对SQL时间类型的操作(获得当前、昨天、前年。。时间)

    Java获得当前时间 java.util.Date date = new java.util.Date(); Timestamp time = new Timestamp(date.getTime() ...

  2. linux 下 NetBeans 字体大小设置

    在linux mint 12下安装了 NetBeans7.1.2使用之后,觉得字体不好看,字体普遍特别大,分三个方面改NetBeans的字体. 1. 代码字体大小 点击NetBeans菜单,工具--& ...

  3. HDU 5430 Reflect

    题意:问在一个圆形的镜面里,从任意一点发出一个光源,经n次反射回到起点的情况数是多少. 解法:直接贴题解吧…… 求1至N+1中与N+1互质的个数,即欧拉函数. 代码: #include<stdi ...

  4. Hadoop序列化

      遗留问题: Hadoop序列化可以复用对象,是在哪里复用的? 介绍Hadoop序列化机制 Hadoop序列化机制详解 Hadoop序列化的核心 Hadoop序列化的比较接口 ObjectWrita ...

  5. hdu5073 简单枚举+精度处理

    其实这题还是挺简单的,因为移动k个星球后,这k个星球的权值就可以变为0,所以只有剩下的本来就是连着的才是最优解,也就是说要动也是动两端的,那么就O(N)枚举一遍动哪些就好了. 我是在杭电oj题目重现的 ...

  6. 【windows核心编程】线程局部存储TLS

    线程局部存储TLS, Thread Local Storage TLS是C/C++运行库的一部分,而非操作系统的一部分. 分为动态TSL 和 静态TLS 一.动态TLS 应用程序通过调用一组4个函数来 ...

  7. qt 设置背景图片

    博客出处:http://www.cppblog.com/qianqian/archive/2010/07/25/121238.htm 工作似乎走上正轨了,上周五的工作是做一个界面,用到QFrame和Q ...

  8. QT-【转】Qt 4迁移至Qt 5

    将Qt 4代码迁移到Qt 5还是比较简单的.实际上,在Qt 5开发过程中就已经注意了与Qt 4代码保持兼容性. 与Qt 3到Qt 4的迁移不同,Qt 5的核心类库并没有做大的API的修改,只有几个新的 ...

  9. Ajax异步请求PHP数据

    来源:http://www.ido321.com/1138.html 接到了老师的一个作业,实现的布局如图: 如果输入了科室ID,科室名字只显示与ID对应的,若没有输入,则显示全部,然后根据I科室名字 ...

  10. 多校5 1001 HDU5781 ATM Mechine 记忆化搜索+概率

    // 多校5 1001 HDU5781 ATM Mechine // http://acm.hdu.edu.cn/search.php?field=problem&key=2016+Multi ...