题解 | #明明的随机数#
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
#include <iostream> using namespace std; int main() { int a, b; cin >> a; int snum[1000] = {0}; int s = 0; while (cin >> b) { bool key = true; // 注意 while 处理多个 case if(s == 0){ snum[s] = b; } for(int temp=0; temp<s; temp++){ if(snum[temp] == b){ key = false; break; } } if(key){ for(int temp = 0; temp < s; temp++){ if(b < snum[temp]){ for(int kk = s; kk >= temp; kk--){ snum[kk+1] = snum[kk]; } snum[temp] = b; break; }else if(snum[temp+1]==0){ snum[temp+1] = b; break; } } s++; } } int yu = 0; while(yu<s){ cout<<snum[yu]<<endl; yu++; } } // 64 位输出请用 printf("%lld")