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<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(找规律)的更多相关文章

  1. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  2. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  3. hdu4952 Number Transformation (找规律)

    2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...

  4. CF456B Fedya and Maths 找规律

    http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...

  5. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  6. 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake

    题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...

  7. 找规律 ZOJ3498 Javabeans

    Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...

  8. C基础之递归(思想很重要,学会找规律)

    递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步 ...

  9. BZOJ-1228 E&D 博弈SG+找啊找啊找规律

    讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...

随机推荐

  1. C++_类和对象

    类和对象 OOP第二课 1 类的构成 1.1 从结构到类 1.2 类的构成 2 成员函数的声明 2.1 普通成员函数形式 2.2 将成员函数以内联函数的形式进行说明 3 对象的定义和使用 3.1 对象 ...

  2. Redis笔记 -- make编译安装报错记录2则(一)

    1.Redis的获取与安装,目前最新稳定版本为4.0.10 Redis:  https://redis.io/download GitHub:  https://github.com/antirez/ ...

  3. Homebrew(brew)安装MySQL成功后无法登录

    Homebrew简称brew,OSX上的软件包管理工具,在Mac终端可以通过brew安装.更新.卸载各种软件,(简直就是神器级武器). 废话不多说,没安装brew自己去百度学习安装,这里就不多说了. ...

  4. 全局变量和局部变量(global关键字)

    1.定义在函数外部的就是全局变量,它的作用域从定义处一直到文件结尾. 2.函数内定义的变量就是局部变量,它的作用域为函数定义范围内. 3.函数之间存在作用域互不影响. 4.函数内访问全局变量需要 gl ...

  5. ruby on rails 环境搭建(mac or ubuntu)

    环境配置前操作 mac: app_store安装x-code ubuntu: 终端->配置文件->首选项->命令->以shell方式登录 安装RVM mac: $ ruby - ...

  6. python教程(三)·函数进阶(下)

    下半部分果然很快到来,这次介绍函数的更高级用法,装饰器! 函数嵌套 先来说说函数嵌套,python中的函数是可以嵌套的,也就是说可以将一个函数放在另一个函数里面,比如: >>> de ...

  7. ACM1005:Number Sequence

    Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) ...

  8. LintCode 896. Prime Product 简明题解

    Given a non-repeating prime array arr, and each prime number is used at most once, find all the prod ...

  9. 详解LeetCode 137. Single Number II

    Given an array of integers, every element appears three times except for one, which appears exactly ...

  10. 20155332 实验二 Java面向对象程序设计

    目录 一.单元测试和TDD 任务一:实现百分制成绩转成"优.良.中.及格.不及格"五级制成绩的功能 任务二:以TDD的方式研究学习StringBuffer 二.面向对象三要素:封装 ...