国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Codeforces 514A Chewbaсca and Number【貪心】這題好勁啊

2019-11-14 10:45:36
字體:
來源:轉載
供稿:網友

A. Chewbaсca and Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digitt means replacing it with digit 9?-?t.

Help Chewbacca to transform the initial number x to the minimum possiblepositive number by inverting some (possibly, zero) digits. The decimal rePResentation of the final number shouldn't start with a zero.

Input

The first line contains a single integer x(1?≤?x?≤?1018) — the number that Luke Skywalker gave to Chewbacca.

Output

Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.

ExamplesInput
27Output
22Input
4545Output
4444

題目大意:

給你一個LL范圍內的數字X,每一位子上的數字t都可以替換為9-t,讓你輸出最小的,不含有前導0的正整數,不能以0開頭。

思路:

貪心角度很好想,ans【i】=min(a【i】,9-a【i】);

一開始讀題沒看到正整數三個字,那么990的ans我認為是0.Wa一發、

后來發現了,那么990的ans我認為是9.又Wa一發、

哦,結果要求沒有0開頭啊。那么ans==900.

這是一道A題.恩.滿滿的Hack點,我不禁開始幻想當時打這場比賽的小伙伴們會Hack多少發。

Ac代碼:

#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define ll __int64char a[200];int ans[200];ll output;int n;int main(){    while(~scanf("%s",a))    {        n=strlen(a);        output=0;        int f=0;        for(int i=0;i<n;i++)        {            ans[i]=min(a[i]-'0',9-a[i]+'0');            if(ans[i]!=0&&f==0)f=1;            if(ans[i]==0&&f==0)ans[i]=max(a[i]-'0',9-a[i]+'0'),f=1;        }        for(int i=0;i<n;i++)        {            output=output*10+ans[i];        }        printf("%I64d/n",output);    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿图什市| 旺苍县| 平江县| 常山县| 苍梧县| 宕昌县| 金湖县| 山东| 潍坊市| 江油市| 芦山县| 阿拉尔市| 加查县| 湾仔区| 惠水县| 邛崃市| 望城县| 余江县| 公主岭市| 东方市| 万安县| 昭平县| 浦东新区| 尼勒克县| 宜丰县| 义乌市| 宝清县| 平罗县| 土默特右旗| 临沂市| 驻马店市| 蕉岭县| 乐平市| 班玛县| 比如县| 桃江县| 靖远县| 罗甸县| 东莞市| 汕尾市| 罗源县|