A. Lucky Conversion
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ainto string b.

Sample test(s)
input
47
74
output
1
input
774
744
output
1
input
777
444
output
3
   不得不承认CF上的题确实质量非常好,这题还是A题就卡了好一阵,思路非常诡异。。
题意:
给出一串字符串,仅仅包括数字4和7 然后再给出还有一个字符串,相同是仅仅包括4和7,长度相同,如今给定两种操作,①:改变a串某位上的数字;②:交换a串随意两位上的数字,求最小操作数 使得a==b
由于是要最小操作数,所以要尽可能的运行交换操作,所以 扫一遍a串,看它和b串的相应位置上的数字是不是同样,若不同,记下4和7不同的个数,当中最大数就是答案。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define LL long long
const int maxn=100050;
char s[maxn],t[maxn];
int main()
{
while(~scanf("%s%s",s,t))
{
int len=strlen(s),cnt1=0,cnt2=0;
for(int i=0;i<len;i++)
{
if(s[i]!=t[i])
{
if(s[i]=='4')
cnt1++;
else
cnt2++;
}
}
printf("%d\n",max(cnt1,cnt2));
}
return 0;
}

Codeforces 145A-Lucky Conversion(规律)的更多相关文章

  1. Lucky Conversion(找规律)

    Description Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive int ...

  2. CodeForces 146A Lucky Ticket

    Lucky Ticket Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  3. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  4. Codeforces 626B Cards(模拟+规律)

    B. Cards time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp ...

  5. Codeforces 121A Lucky Sum

    Lucky Sum Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Origi ...

  6. codeforces 630 I(规律&&组合)

    I - Parking Lot Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  7. codeforces 630C Lucky Numbers

    C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...

  8. 数据结构(线段树):CodeForces 145E Lucky Queries

    E. Lucky Queries time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  9. CodeForces 146E - Lucky Subsequence DP+扩展欧几里德求逆元

    题意: 一个数只含有4,7就是lucky数...现在有一串长度为n的数...问这列数有多少个长度为k子串..这些子串不含两个相同的lucky数... 子串的定义..是从这列数中选出的数..只要序号不同 ...

随机推荐

  1. 目标决定人生——没有目标就失去一切 (没有目标的奋斗是浪费青春,比如交了钱却不去参加考试、让时间白白溜走。根据目标与定位来选择最合适的企业。人生要算总账)good

    没有目标就失去一切 刚毕业那会儿,幼稚得可笑,老跟同学打电话,明面上聊聊近况,暗地里比较.你要比我工资多一百块,心里特不平衡,凭什么呀,在学校那会儿公认的我比你强.你要带个头衔,而我啥也不是,普通员工 ...

  2. jquery09--Callbacks : 回调对象

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  3. 什么时候用button,什么时候用a标签

    什么时候用button,什么时候用a标签 一.问题 能实现链接功能的标签一般就a标签,button标签,input submit标签 input submit肯定是提交表单的时候用 那什么时候用but ...

  4. jq---方法总结

    1. 什么是jQuery 在使用jQuery之前,我们必须先了解什么是jQuery,它能够干什么(不然我们为啥要用它). jQuery是一个非常流行的快速.小巧.功能强大的开源JavaScript库. ...

  5. C++的继承和Java继承的比较

    在C++中继承可分为公有继承(public)保护继承(protected)和私有继承(private),而在Java中默认只有一种继承(相当于C++中的公有继承)下面我们来看一段代码 #include ...

  6. API(Application Programming Interface,应用程序编程接口)

    API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码 ...

  7. idea配置spark运行模式

    1. 配置运行参数: Menu -> Run -> Edit Configurations -> 选择 + -> Application   -Dspark.master=lo ...

  8. Python修改文件内容

    工作中要写个脚本来修改文件的内容,然后就写了一个刷子: #coding:utf8 import os def modify_file(old_file, new_version, old_versio ...

  9. Python爬虫之『urlopen』

    本文以爬取百度首页为示例来学习,python版本为python3.6.7,完整代码会在文章末附上 本次学习所用到的python框架:urllib.request 本次学习所用到的函数: urllib. ...

  10. WPF通用框架 数据库结构

    前言 由於技術轉型, 目前大部分工作都是WPF為主, 但是趨於如今想在網絡上找一套能夠滿意的WPF權限管理框架太難, 因為WinForm那時候是有一套改寫過的權限框架, 所以數據庫設計這塊已經有了一個 ...