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

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

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

2019-11-14 11:35:08
字體:
來源:轉載
供稿:網友

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上饶县| 乌鲁木齐市| 玉田县| 滨海县| 三门峡市| 塔城市| 呈贡县| 湖南省| 大兴区| 突泉县| 蕲春县| 平昌县| 台湾省| 静宁县| 南投市| 和平区| 四川省| 大安市| 海林市| 门源| 监利县| 安溪县| 嵩明县| 垣曲县| 枝江市| 冕宁县| 梨树县| 延长县| 棋牌| 凤台县| 抚松县| 洮南市| 安图县| 天长市| 山东省| 凤城市| 灵武市| 丹阳市| 遂川县| 东方市| 克什克腾旗|