TopCoder SRM 664 Div2 Level One
2015-08-02 21:17
489 查看
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:
BearCheatsMethod:
eyesightParameters:
int, intReturns:
stringMethod 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)
80723072
Returns: “happy”
Limak wants to change 8072 into 3072. He can do that by changing the digit 8 to a 3.
1)
508540
Returns: “glasses”
Limak would need to change two digits, but he only has the time to change at most one.
2)
854000854000
Returns: “happy”
It is possible that Limak read the number correctly. If that happens, he will not change any digits.
3)
16
Returns: “happy”
4)
385900123000
Returns: “glasses”
题意
熊孩子检查视力,医生给了一个数字A,熊孩子给了一个数字B,然后医生出去了,熊孩子想改变数字A让自己通过检查,最多更改一位,不能增加或减少数字,问能否令A==B题解
一位一位判断就好。。。#include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; class BearCheats { public: string eyesight(int, int); }; string BearCheats::eyesight(int A, int B) { if(A==B) return string("happy"); int ans=0; while(A&&B&&ans<=1) { if(A%10!=B%10) ans++; A/=10; B/=10; } if(ans==1&&A==0&&B==0) return string("happy"); else return string("glasses"); }
相关文章推荐
- 关于在使用tomcat做开发测试的某些时候无端报ClassNotFound异常的解决方法
- 文本分块切割
- linux_c开发(5-4)进程间通讯_共享内存通讯
- centos下安装axel
- nginx 平滑升级tengine
- 平面设计入门之Mac OS photoshop安装
- 一个没水平的钓鱼网站黑三个人:人们的安全意识和安全知识的缺失
- 在 Linux 下安装基于 Python 的机器学习编程环境
- 《Linux系统精讲》学习总结(二)
- vRedHat Enterprise Linux 6.4使用Centos 6 的yum源
- centos下的tomcat的安装
- 基于规则引擎的电信CRM系统架构研究
- Shell 学习17 - Shell for 循环
- Linux中的Samba配置流程
- linux 删除和移动的常用快捷键
- OpenGL 列主序 矩阵
- nginx主模块指令
- Shell 学习16 - Shell case esac 语句
- Shell 学习15 - Shell if else 语句
- UVA 11992 - Fast Matrix Operations