移动到末尾(蓝桥杯)

复制代码
#include <stdio.h>
#include <stdlib.h>

#define N 1000   //双指针思想
int main(int argc, char *argv[])
{
  int n;
  int s[N];
  scanf("%d",&n);
  for(int i = 0 ; i < n ; i++)
    scanf("%d",&s[i]);
  int j = 0;              
  for(int i = 0 ; i < n ; i++) 
  {
     if(s[i] != 0 )    
      {
        int t = s[j];
          s[j++] = s[i];
          s[i] = t;
      }
  }
  for(int i = 0 ; i < n ; i++)
   printf("%d ",s[i]);
  return 0;
}
相关推荐
CV-Climber5 小时前
检索技术的实际应用
人工智能·算法
hhzz6 小时前
Tiger AI Platform平台中增加人脸识别功能
图像处理·人工智能·算法·计算机视觉·大模型
从零开始的代码生活_7 小时前
C++ 继承详解:访问控制、对象模型、菱形继承与设计取舍
开发语言·c++·后端·学习·算法
TsingtaoAI7 小时前
3D高斯泼溅技术发展及其在具身智能领域的应用综述
人工智能·算法·ai·具身智能·高斯泼溅
atunet7 小时前
关于图算法中的连通分量检测与最小割问题7
算法
心运软件8 小时前
银行客户流失预测(Python 完整实战)
算法
邪神与厨二病8 小时前
牛客周赛 Round 153
python·算法
qizayaoshuap10 小时前
# ❌ 井字棋 — 鸿蒙ArkTS Minimax AI算法与博弈系统设计
人工智能·算法·华为·harmonyos
皓月斯语10 小时前
B3842 [GESP202306 三级] 春游 题解
数据结构·c++·算法·题解