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 ...
随机推荐
- Liunx系统学习一,liunx系统的目录结构及含义
LIUNX系统目录结构: “/” ===>这是linux文件系统的入口,也是整个linux文件系统的根目录,linux不同于windows,没有所谓的C,D,E盘,整个liunx只有一个根分区 ...
- ecshop 二次开发及模板标签
ecs_account_log // 用户账目日志表 ecs_activity // 活动表(代码,名称,开始,结束,描述) ecs_ad // 广告表(位置,类型,名称,链接,图片,开始,结 ...
- C# C/S 结构操作Ini系统文件
Winfrom 开发时,有时会将一些系统某个设置保存到Ini 类型的文件中.下面提供操作Ini 文件的代码: public static class IniFiles { [DllImport(&qu ...
- C#网络资源列表
1, http://club.topsage.com/thread-371996-1-1.html
- Claim-based-security for ASP.NET Web APIs using DotNetOpenAuth
Recently I worked with a customer assisting them in implementing their Web APIs using the new ASP.NE ...
- 《浅析各类DDoS攻击放大技术》
原文链接:http://www.freebuf.com/articles/network/76021.html FreeBuf曾报道过,BT种子协议家族漏洞可用作反射分布式拒绝服务攻击(DRDoS a ...
- 【九度OJ】题目1078-二叉树遍历
题目 这道题和后面的两道题,题目1201和题目1009,主要内容是对递归的实现,在逻辑上,递归是容易理解的,这种实现方式和我们思考的方式是相吻合的.但是在转换为计算机语言时,要明确告知计算机应该从哪里 ...
- mybatis系列-06-输入映射
通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型 6.1 传递pojo的包装对象 6.1.1 需求 完成用户信息的综合查询,需要 ...
- nodejs 5.2.0文档自翻译——HTTP模块
HTTP Class: http.Agent new Agent([options]) agent.destroy() agent.freeSockets agent.getName(options) ...
- hive优化之------控制hive任务中的map数和reduce数
一. 控制hive任务中的map数: 1. 通常情况下,作业会通过input的目录产生一个或者多个map任务. 主要的决定因素有: input的文件总个数,input的文件大小,集群设置的 ...