永发信息网

c语言如何对数字进行排序和去重

答案:3  悬赏:40  手机版
解决时间 2021-04-05 15:33
  • 提问者网友:原来太熟悉了会陌生
  • 2021-04-05 09:03
c语言如何对数字进行排序和去重
最佳答案
  • 五星知识达人网友:毛毛
  • 2021-04-05 09:28
百度冒泡排序,去重可以建一个新的数组
全部回答
  • 1楼网友:拜訪者
  • 2021-04-05 10:33
#include #include #include using namespace std; int main() { int n,a,i; setm; while(scanf("%d",&n)!=EOF) { for(i=0;i { scanf("%d",&a); m.insert(a); } set::iterator it; printf("%d\n",m.size()); for(it=m.begin();it!=m.end();it++) { if(it==m.begin()) printf("%d",*it); else printf(" %d",*it); } printf("\n"); m.clear(); } return 0; }
  • 2楼网友:逐風
  • 2021-04-05 10:20
nsmutablearray *p = [[nsmutablearray alloc] initwithobjects:@"3",@"5",@"4",@"1",nil]; for (int i = 0; i<[p count]; i++) { for (int j=i+1; j<[p count]; j++) { int a = [[p objectatindex:i] intvalue]; nslog(@"a = %d",a); int b = [[p objectatindex:j] intvalue]; nslog(@"b = %d",b); nslog(@"------"); if (a > b) { [p replaceobjectatindex:i withobject:[nsstring stringwithformat:@"%d",b]]; [p replaceobjectatindex:j withobject:[nsstring stringwithformat:@"%d",a]]; }for (int i = 0; i<[p count]; i++) { nslog(@"%@",[p objectatindex:i]);} }}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯