题解 | 左侧严格小于计数

左侧严格小于计数

https://www.nowcoder.com/practice/c5922c6cdd1445749bd42f586c422435

#include <stdio.h>
int main() {
    int n;
    scanf("%d",&n);
    int a[n];
    int b[n];
    int count=0;
    for(int i =0;i<n;i++){
        scanf("%d ",&a[i]);//输入数组a
    }
    for(int i = 0;i<n;i++){
        for(int j =0;j<=i;j++){//嵌套循环 再依次扫描a[i]中 在依次进行比较 需要两次循环
            if(a[j]<a[i]) count++;//如果前面的有小于数组当前元素的 计数器++
        }
        b[i]=count;//结果加入数组b
        count = 0;//重置计数器
    }
    for(int i =0;i<n;i++){
        printf("%d ",b[i]);
    }
    return 0;
}

全部评论

相关推荐

04-03 09:32
已编辑
华南农业大学 golang
我的代码出BUG了:"晚点发个邮件调整一下时间",你收到新的邮件没,如果没有收到新的邮件,那就需要进入面试链接留痕,否则系统会判定你迟到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务