国产探花免费观看_亚洲丰满少妇自慰呻吟_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);    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固镇县| 如皋市| 温宿县| 射阳县| 杂多县| 孟津县| 南和县| 基隆市| 丰台区| 万载县| 获嘉县| 清水县| 黔江区| 陇南市| 兰考县| 南川市| 石嘴山市| 微山县| 阳原县| 垦利县| 岳阳县| 茂名市| 台东县| 秀山| 循化| 博湖县| 天祝| 潢川县| 灌南县| 崇信县| 沅江市| 长春市| 普定县| 金山区| 大竹县| 永和县| 淳化县| 惠水县| 临沧市| 射洪县| 吴忠市|