Lucky Conversion(找规律)
Description
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Petya can perform operations of two types:
- replace any one digit from string a by its opposite (i.e., replace 4 by 7 and 7 by 4);
- swap any pair of digits in string a.
Petya is interested in the minimum number of operations that are needed to make string a equal to string b. Help him with the task.
Input
The first and the second line contains strings a and b, correspondingly. Strings a and b have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105.
Output
Print on the single line the single number — the minimum number of operations needed to convert string a into string b.
Sample Input
47
74
1
774
744
1
777
444
3 题目意思:给你两个字符串a,b,a,b都是由4和7组成的。a串中的4和7可以通过交换位置或者替换(4替换成7,7替换成4),
问最少多少步就能得到b串。 解题思路:这算是一道找规律的题了,其实可以这样做,统计a串和b串不同的字符在b串中表现是4还是7,记录一下个数,
4的个数和7的个数可以相互抵消来表示交换,剩下不能抵消的可以用来替换。抵消的次数加上替换的次数就是需要的步数。 上代码:
#include<stdio.h>
#include<string.h>
int main()
{
char a[],b[];
int k,i,count_7=,count_4=,count=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
gets(a);
gets(b);
k=strlen(a);
for(i=; i<k; i++)
{
if(a[i]==b[i])
continue;
else
{
if(b[i]=='')
count_7++;
else
count_4++;
}
}
if(count_7>=count_4)
count=count_4+count_7-count_4;
else if(count_7<count_4)
count=count_7+count_4-count_7;
printf("%d\n",count);
return ;
}
Lucky Conversion(找规律)的更多相关文章
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
- HDU 5703 Desert 水题 找规律
已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...
- hdu4952 Number Transformation (找规律)
2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...
- CF456B Fedya and Maths 找规律
http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
- 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake
题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...
- 找规律 ZOJ3498 Javabeans
Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...
- C基础之递归(思想很重要,学会找规律)
递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步 ...
- BZOJ-1228 E&D 博弈SG+找啊找啊找规律
讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...
随机推荐
- MySQL学习【第八篇索引优化】
一.建立索引的原则(规范) 1.选择唯一性索引 只要可以创建唯一性索引的,一律创建唯一索引(因为速度快呀) 判断是否能创建唯一索引,用count(列名),count(distinct(列名))一样就能 ...
- python3>日期和时间
阅读目录 1.python3日期和时间 2.时间元组 3.获取格式化的时间 4.格式化日期 5.获取月日历 6.Time模块 7.datetime模块 回到顶部 1.python3日期和时间 Pyth ...
- mac安装配置mysql
目录 mac安装配置mysql 1.mysql的安装 2.设置root用户的密码 3.分别执行一下命令 4.配置mysql环境变量 mac安装配置mysql 1.mysql的安装 安装过程十分简单 ...
- webpack管理输出
管理html的bundle依赖 html-webpack-plugin可以自动给html添加bundle文件 npm install --save-dev html-webpack-plugin co ...
- 解决webview上移
//解决webview上移 $(".webView").blur(function() { setTimeout(function() { var scrollHeight = d ...
- pyhton3解决"tuple parameter unpacking is not supported"问题
准备将键值对中的键与值对调,结果第10行出了bug,显示"tuple parameter unpacking is not supported" 解决方法:将map(lambda( ...
- python3 用户登录验证的小功能
用户登录验证,记录一下,还需要修改黑名单不合理 #!/usr/bin/env python3 ''' 需求:编写登录接口 1.输入用户名和密码 2.验证用户密码成功后输出欢迎消息 3.3次没有验证通过 ...
- Python的print的底层实现
默认调用 sys.stdout.write() 方法 import sys sys.stdout.write("hello") 会在控制台打印:hello
- Framwork框架-网络客户端的使用
1.引入头文件 #include "Comm.h" 2.派生自框架基类CProtocolCpMgr class NetManager : public CProtocolCpMgr ...
- Scala数组操作
数组操作 初始化固定长度的数组 // 初始化长度为10的数组 val array = new Array[Int](10) // 初始化创建含有hello与Scala的数组 val s = Array ...