蒟蒻求助!只AC了两个点!
查看原帖
蒟蒻求助!只AC了两个点!
604622
achjuncool楼主2022/5/31 20:33

qwq

思路:每次选出最大的并标记,进行k次,最后输出时,被标记的不输出

代码:

#include <iostream>
using namespace std;
int main(){
	string n;
	int a[251] = {}, k, maxn;
	cin >> n >> k;
	int len = n.length();
	for(int i = 1; i <= len; i++) a[i] = n[i - 1] - '0'; //字符串-->数组 
	for(int i = 1; i <= k; i++){
		maxn = 0;
		for(int j = 1; j <= len; j++){ //遍历整个数组,找出最大的 
			if(a[j] > maxn){
				maxn = j;
			}
		}
		a[maxn] = -1; //标记 
	}
	for(int i = 1; i <= len; i++){
		if(a[i] > -1){
			cout << a[i]; //输出 
		}
	}
	cout << endl;
	return 0; //结束 
}
2022/5/31 20:33
加载中...