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

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

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

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

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);    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金溪县| 冕宁县| 江达县| 龙海市| 曲靖市| 宣恩县| 渝北区| 南乐县| 永福县| 库车县| 克东县| 兴义市| 闻喜县| 乌兰察布市| 萨迦县| 佛山市| 伊春市| 满洲里市| 鱼台县| 墨竹工卡县| 西贡区| 新竹县| 凤凰县| 磴口县| 商城县| 太白县| 德令哈市| 奉新县| 金乡县| 新乡县| 平江县| 将乐县| 惠安县| 陇川县| 巴东县| 仁怀市| 通化市| 青州市| 厦门市| 潮州市| 浏阳市|