标签:hdu
3 3 1 2 4 0 0
1 2 3 4
#include <iostream> using namespace std; int main() { int n, m; while (cin >> n>> m && n&& m) { int a[110], b[110], num=0, flag=0; for (int i = 0; i<n; i++) { cin >> a[i]; } for (int i=0; i<n; i++) { if (a[i] > m && flag!=1) { flag++; b[num]= m; num++; i--; } else { b[num] = a[i]; num++; } } for (int i=0;i<num-1;i++) { cout << b[i] << " "; } cout << b[num-1] <<endl; } return 0; }
#include<stdio.h> int main() { int n,m,a[100],i; while(scanf("%d %d",&n,&m)!=EOF && (n||m)) { for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=n-1;i>=0;i--) { if(a[i]>m) a[i+1]=a[i]; else { a[i+1]=m; break; } } printf("%d",a[0]); for (i=1; i<n+1; i++) printf(" %d",a[i]); printf("\n"); } return 0; }
标签:hdu
原文地址:http://blog.csdn.net/xiaotan1314/article/details/45974461