记录string的妙用
生活随笔
收集整理的這篇文章主要介紹了
记录string的妙用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
P1106 刪數(shù)問題
?
題目描述
鍵盤輸入一個高精度的正整數(shù)N,去掉其中任意k個數(shù)字后剩下的數(shù)字按原左右次序?qū)⒔M成一個新的正整數(shù)。編程對給定的N和k,尋找一種方案使得剩下的數(shù)字組成的新數(shù)最小。
輸出應包括所去掉的數(shù)字的位置和組成的新的正整數(shù)。(N不超過250位) 輸入數(shù)據(jù)均不需判錯。
輸入輸出格式
輸入格式:?
n (高精度的正整數(shù))
k (需要刪除的數(shù)字個數(shù))
?
輸出格式:?
最后剩下的最小數(shù)。
?
輸入輸出樣例
輸入樣例#1:175438 4 輸出樣例#1:
13
——————————————————————————————
記錄一波代碼而已 erase的妙用啊QAQ #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<string> #define LL long long using namespace std; int read(){int ans=0,f=1,c=getchar();while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}return ans*f; } string s; int n,now; int main() {cin>>s;n=read();for(int i=0;i<n;i++){now=0;while(now<s.size()-1&&s[now]<=s[now+1]) now++;s.erase(now,1);}while(s.size()>1&&s[0]=='0') s.erase(0,1);cout<<s;return 0; } View Code
P1012 拼數(shù)
題目描述
設有n個正整數(shù)(n≤20),將它們聯(lián)接成一排,組成一個最大的多位整數(shù)。
例如:n=3時,3個整數(shù)13,312,343聯(lián)接成的最大整數(shù)為:34331213
又如:n=4時,4個整數(shù)7,13,4,246聯(lián)接成的最大整數(shù)為:7424613
輸入輸出格式
輸入格式:?
第一行,一個正整數(shù)n。
第二行,n個正整數(shù)。
?
輸出格式:?
一個正整數(shù),表示最大的整數(shù)
?
輸入輸出樣例
輸入樣例#1:3 13 312 343 輸出樣例#1:
34331213
——————————————————————————
string的sort #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #define LL long long using namespace std; int read(){int ans=0,f=1,c=getchar();while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}return ans*f; } int n; string s[55]; bool cmp(string a,string b){return a+b>b+a;} int main() {n=read();for(int i=1;i<=n;i++) cin>>s[i];sort(s+1,s+1+n,cmp);for(int i=1;i<=n;i++) cout<<s[i];return 0; } View Code
?
轉(zhuǎn)載于:https://www.cnblogs.com/lyzuikeai/p/7283890.html
總結(jié)
以上是生活随笔為你收集整理的记录string的妙用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: alloc、init你弄懂50%了吗?
- 下一篇: 反编译别人的app