题解 | #序列中删除指定数字#
序列中删除指定数字
https://www.nowcoder.com/practice/7bbcdd2177a445a9b66da79512b32dd7
#include <iostream> using namespace std; int main() { int n,x,temp; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>x; a[i]=x; } cin>>temp; // for(int i=0;i<n;i++){ // if(a[i]!=temp){ // cout<<a[i]<<" "; // } // } int i=0; int j=0; //i一定<=j for(j=0;j<n;j++){ if(a[j]!=temp){ a[i++]=a[j]; } } for(int z=0;z<i;z++){ cout<<a[z]<<" "; } cout<<endl; return 0; } // 64 位输出请用 printf("%lld")