日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

XidianOJ 1123 K=1 Problem of Orz Pandas

發布時間:2023/12/18 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 XidianOJ 1123 K=1 Problem of Orz Pandas 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

One panda named orz is playing a interesting game, he gets a big integer Num and an integer K. In this game, he can exchange two single numbers in Num. For example, he can get 1243 from 3241 by exchange 1 and 3.But orz can exchange at most K times. So what’s the biggest number after at most K times operations?

However, a VIP (Very Important Panda) of ACM/OPPC (Orz Panda Programming Contest) comittee thought this problem was too hard for Orz Pandas. So he simplified this problem with constraint K=1. Your task is to solve the simplified problem.

?

輸入

Multiple cases. For each case:
The first line is an integer Num. 0 ≤ Num ≤ 10
1000, and it is guaranteed that Num is a legal integer and doesn’t contain any leading zero

?

輸出

For each test case, print the biggest number after at most 1 times operation in a line.

--正文 字符串讀取數,貪心找可能的數進行交換 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; char num[1001];int findMax(char* num){int len = strlen(num);int max = -1,maxi;int i;for (i=0;i<len;i++){if (num[i] - '0' >= max) {max = num[i] - '0';maxi = i;}}return maxi; }int main(){while (scanf("%s",num) != EOF){char* begin = num;int len = strlen(num);int total = 0;bool over = false;while (!over){int maxi = findMax(&num[total]) + total;int now = total;while (num[now] == num[maxi] && now < maxi) now++;if (now == maxi) {total = maxi+1;if (num[total] == '\0') break;continue;}else {char temp = num[now];num[now] = num[maxi];num[maxi] = temp;break;}}printf("%s\n",begin);}return 0; }

?

轉載于:https://www.cnblogs.com/ToTOrz/p/6135347.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的XidianOJ 1123 K=1 Problem of Orz Pandas的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。