标签:数据 amp std scan lock block cst scanf pat
标签(空格分隔): PAT
解决方法:贪心法
#include <cstdio>
int main() {
int count[10];
for (int i = 0; i < 10; i++) {
scanf("%d", &count[i]);
}
for (int i = 1; i < 10; i++) {
if (count[i] > 0) {
printf("%d", i);
count[i]--;
break;
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < count[i]; j++) {
printf("%d", i);
}
}
return 0;
}
下面是我只能过三个数据点的代码
#include <cstdio>
int num[15];
int main() {
for (int i = 0; i < 10; i++) {
scanf("%d", &num[i]);
}
for (int i = 1; i < 10; i++) {
while (num[i] != 0) {
printf("%d", i);
num[i]--;
break;
}
break;
}
for (int i = 0; i < 10; i++) {
while (num[i] > 0) {
printf("%d", i);
num[i]--;
}
}
return 0;
}
标签:数据 amp std scan lock block cst scanf pat
原文地址:https://www.cnblogs.com/Kirarrr/p/10340055.html