SDUT 2072 删数问题
2017-04-08 15:46
267 查看
删数问题
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description
键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。
Input
输入有多组 每组包括原始数n,要去掉的数字数s;
Output
输出去掉s个数后最小的数
Example Input
178543 4
Example Output
13
这道题wa了很多次,其中有没处理前导0,输出的数据是000,输入数据是000等问题,还有手误a[i]<=a[i+1]写成a[i]<a[i+1]导致像80023 3这样的数据错误。
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic Discuss
Problem Description
键盘输入一个高精度的正整数n(≤100位),去掉其中任意s个数字后剩下的数字按照原来的左右次序组成一个新的正整数。编程对给定的n与s,寻找一种方案,使得剩下的数字组成的新数最小。
Input
输入有多组 每组包括原始数n,要去掉的数字数s;
Output
输出去掉s个数后最小的数
Example Input
178543 4
Example Output
13
这道题wa了很多次,其中有没处理前导0,输出的数据是000,输入数据是000等问题,还有手误a[i]<=a[i+1]写成a[i]<a[i+1]导致像80023 3这样的数据错误。
#include <bits/stdc++.h> using namespace std; int main() { char a[110]; int s,i; while(cin>>a) { cin>>s; int t = s; int len2 = strlen(a); if(len2<=s) { cout<<"0"<<endl; continue; } while(s>0) { i = 0; int len = strlen(a); while(i < len && a[i]<=a[i+1]) i++; while(i<len) { a[i] = a[i+1]; i++; } s--; } i=0; //if(a[0]=='0') //{ while(a[i]=='0') i++; // } if(i==len2-t) cout<<"0"; for(int j = i;j < len2-t;j++) printf("%c",a[j]); cout<<endl; } return 0; }
//101 1 80023 3
相关文章推荐
- sdut 2072 删数问题 删除几个数字之后求最大数
- SDUT 2072 删数问题
- sdut2072 删数问题
- ACM 删数问题 SDUT 2072
- SDUT-不敢死队问题
- SDUT 1197----约瑟夫问题
- SDUT 1304-取数字问题(DFS)
- SDUT 1867 最短路径问题
- SDUT 2073----活动选择问题
- SDUT排序问题
- sdut.acm1197约瑟夫问题
- SDUT 3346 数据结构实验之二叉树七:叶子问题
- 【2056】不敢死队问题(循环链表)SDUT
- SDUT 叶子问题
- SDUTRescue The Princess(数学问题)
- sdut-1722整数因子分解问题
- 全排列问题 SDUT 4165
- sdut 2168 Mathmen 优先队列处理区间问题
- SDUT_2080最长公共子序列问题
- SDUT_数字三角形问题_动态规划