题解 | #计算某字母出现次数#
明明的随机数
http://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
C语言算法:
注意判断输入是否结束:while (scanf("%d", &x) != EOF)
#include<stdio.h> #include<stdlib.h> #include<string.h> int cmp(int *a, int *b) { return *a - *b; } int main() { int j = 0; int x = 0, input[1000] = { 0 }, output[1000] = { 0 }; while (scanf("%d", &x) != EOF) { // printf("x=%d\n",x); for (int i = 0; i < x; i++) { scanf("%d", (input + i)); } // printf("\n shurujiesu\n"); qsort(input, x, sizeof(int), cmp); for (int i = 0; i < x; i++) { if (input[i] != input[i + 1]) { // output[j++] = input[i]; printf("%d\n", input[i]); } } } getchar(); return 0; }