博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lucky Conversion(找规律)
阅读量:4323 次
发布时间:2019-06-06

本文共 1640 字,大约阅读时间需要 5 分钟。

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

Input
47 74
Output
1
Input
774 744
Output
1
Input
777 444
Output
3 题目意思:给你两个字符串a,b,a,b都是由4和7组成的。a串中的4和7可以通过交换位置或者替换(4替换成7,7替换成4), 问最少多少步就能得到b串。 解题思路:这算是一道找规律的题了,其实可以这样做,统计a串和b串不同的字符在b串中表现是4还是7,记录一下个数, 4的个数和7的个数可以相互抵消来表示交换,剩下不能抵消的可以用来替换。抵消的次数加上替换的次数就是需要的步数。 上代码:
#include
#include
int main(){ char a[100001],b[100001]; int k,i,count_7=0,count_4=0,count=0; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); gets(a); gets(b); k=strlen(a); for(i=0; i
=count_4) count=count_4+count_7-count_4; else if(count_7
 

 

 

转载于:https://www.cnblogs.com/wkfvawl/p/8687175.html

你可能感兴趣的文章
ASP.NET MVC 3 扩展生成 HTML 的 Input 元素
查看>>
LeetCode 234. Palindrome Linked List
查看>>
编译HBase1.0.0-cdh5.4.2版本
查看>>
结构体指针
查看>>
迭代器
查看>>
Food HDU - 4292 (结点容量 拆点) Dinic
查看>>
Ubuntu安装Sun JDK及如何设置默认java JDK
查看>>
[经典算法] 排列组合-N元素集合的M元素子集
查看>>
Codeforces 279D The Minimum Number of Variables 状压dp
查看>>
打分排序系统漫谈2 - 点赞量?点赞率?! 置信区间!
查看>>
valgrind检测linux程序内存泄露
查看>>
MSP430(F149)学习笔记——红外接收
查看>>
cef3的各个接口你知道几个
查看>>
Hadoop以及组件介绍
查看>>
1020 Tree Traversals (25)(25 point(s))
查看>>
第一次作业
查看>>
“==”运算符与equals()
查看>>
单工、半双工和全双工的定义
查看>>
Hdu【线段树】基础题.cpp
查看>>
时钟系统
查看>>