TC SRM 664 div2 A BearCheats 暴力
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 暴力的更多相关文章
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...
- TC SRM 665 DIV2 B LuckyCycle 暴力
LuckyCycleTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...
- TC SRM 664 div2 B BearPlaysDiv2 bfs
BearPlaysDiv2 Problem Statement Limak is a little bear who loves to play. Today he is playing by ...
- topcpder SRM 664 div2 A,B,C BearCheats , BearPlays equalPiles , BearSorts (映射)
A题,熊孩子测视力,水题,题意就是判断一下两个数对应位不相同的数字有多少个. #include<bits/stdc++.h> using namespace std; class Bear ...
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- TC SRM 607 DIV2
求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了. 复习了一下求最长子回文串的算法,发现可以类似解决. 给相邻字符之间添加一个'@'字符,这样所有的回文串都是奇数长 ...
- TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 591 DIV2 1000
很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...
随机推荐
- 【转】如何在IOS中使用3D UI - CALayer的透视投影
原文网址:http://www.tairan.com/archives/2041/ 例子代码可以在 http://www.tairan.com/thread-3607-1-1.html 下载 iOS的 ...
- css的框架——global.css
global.css,一般这个css文件是用于装全站主要框架css样式代码. “global”翻译为全局.全部.从翻译中大家也能理解global.css用于做什么.大站常常用于装全站公共的CSS样式选 ...
- JavaScript 现状:方言篇
导读 JavaScript 和其他编程语言有一个很大的不同,它不像单纯的一个语言,而像一个由众多方言组成大家族.从 2009 年 CoffeeScript 出现开始,近几年出现了大量基于 JavaSc ...
- [Everyday Mathematics]20150111
设 $n$ 阶方阵 $A=(\al_1,\cdots,\al_n)$ 非奇异, $B=(0,\al_2,\cdots,\al_n)$. 试证: $BA^{-1}$, $A^{-1}B$ 的秩均为 $n ...
- How to Calculate difference between two dates in C# z
Do you need to find the difference in number of days, hours or even minute between the two date rang ...
- POST 一张 图像的调试来认识 http post
上传图片的详细 2559字节
- 复制表的sql语句
1.sqlserver 原表存在:insert into a select * from b 原表不存在:select * into a from b 2.mysql.oracle 原表存在:inse ...
- 【Hadoop代码笔记】Hadoop作业提交之TaskTracker 启动task
一.概要描述 在上篇博文描述了TaskTracker从Jobtracker如何从JobTracker获取到要执行的Task.在从JobTracker获取到LaunchTaskAction后,执行add ...
- 在linux上用dd命令实现ghost功能
ghost和g4l 安装操作系统,速度太慢,整个过程太冗长乏味了. 安装过程中,需要回答若干问题,系统需要安装无数个软件,创建和写入无数的文件.因为涉及到大量的文件定位和读写,速度一定是快不起来的. ...
- 见过的最好AWK手册
原文: http://linuxfire.com.cn/~lily/awk.html 简体中文版由bones7456 (http://li2z.cn)整理. 原文:应该是 http://phi.sin ...