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 ...
随机推荐
- python3爬虫-通过requests爬取图虫网
import requests from fake_useragent import UserAgent from requests.exceptions import Timeout from ur ...
- 小白的Unity5之路(二)镜头平滑跟随角色
这次要完成Camera跟随Player移动, 首先考虑Camera的跟随目标target和平滑移动速度smothing再考虑Camera与Player的偏移量(就是Camera与Player有一个永恒 ...
- 关于使用iframe,父元素无法获得子iframe对的元素
首先确定自己写的方法对不对: $(document.getElementById('iframe的ID').contentWindow.document.body).find("要获得的元素 ...
- redis学习指南
一.redis安装 # 安装最新版 yum install -y epel-release vim atop htop net-tools git wget gcc-c++ yum clean all ...
- python从Excel中提取邮箱
从各个城市的律师协会去爬取的律师的招聘信息,可是邮箱在招聘简介里面,所有需要写个脚本去提取邮箱 import pandas as pd import re regex = r"([-_a-z ...
- git——本地项目上传到git
1.对于github相信大家写自动化代码的人都不陌生,而且这也可以说是你进军自动化的一项必须解锁的技能,今天抽空开始整理笔记,顺便整理下github的基本使用,从本地上传代码托管: 一.从无到有:先注 ...
- (数据科学学习手札53)Python中tqdm模块的用法
一.简介 tqdm是Python中专门用于进度条美化的模块,通过在非while的循环体内嵌入tqdm,可以得到一个能更好展现程序运行过程的提示进度条,本文就将针对tqdm的基本用法进行介绍. 二.基本 ...
- 20155337祁家伟 2016-2017-2 《Java程序设计》第2周学习总结
20155337 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 这周我学习了从JDK到IDE的学习内容,简单来说分为以下几个部分 使用命令行和IDE两种方式 ...
- SRM 563 500pts SpellCards
SpellCards 题意: 有n张符卡排成一个队列,每张符卡有两个属性,等级li和伤害di. 两种操作: 1.把队首的符卡移动到队尾:2.使用队首的符卡,对敌人造成di点伤害,并丢弃队首的li张符卡 ...
- 解决非controller使用,@Autowired或者@Resource注解注入Mapper接口为null的问题
知识点:在service层中注入其它的service接口或者mapper接口都是可以的 但是在封装的Utils工具类中或者非controller普通类中使用@Autowired@Resource注解注 ...