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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵州省| 定西市| 缙云县| 电白县| 岑溪市| 门源| 西乡县| 海晏县| 永新县| 隆回县| 石屏县| 湾仔区| 化隆| 格尔木市| 哈尔滨市| 铁力市| 满洲里市| 竹北市| 哈尔滨市| 积石山| 黄大仙区| 如皋市| 仁化县| 黎平县| 紫阳县| 昌宁县| 疏附县| 安国市| 丰台区| 万荣县| 巴彦淖尔市| 勐海县| 林甸县| 江源县| 南昌县| 龙泉市| 黎川县| 轮台县| 昌平区| 清涧县| 溆浦县|