1 条题解
-
0
C :
#include<stdio.h> int main(){ int n; scanf("%d",&n); int a[n],b[n],i; for(i=0;i < n;i++){ scanf("%d",&a[i]); } //求出数各个数位的和放在数组中 for(i = 0;i < n;i++){ b[i] = a[i] / 10000+a[i] / 1000 % 10 + a[i] / 100 % 10+ a[i] / 10 % 10+a[i] % 10; } //排序 int j,k,temp; for(i = 0;i < n-1;i++){ k = i; for(j = i + 1;j < n;j++){ if(b[j] < b[k]) k = j; } if(k != i){ temp = b[i]; b[i] = b[k]; b[k] = temp; } } for(i = 0;i < n;i++){ printf("%d ",b[i]); } return 0; }
C++ :
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(){ int n,i,j,f[30000],a[30000],t; cin>>n; for(i=0;i<n;i++){ cin>>f[i]; while(f[i]!=0){ a[i]+=f[i]%10; f[i]/=10; } } for(i=0;i<n;i++){ for(j=0;j<n-i-1;j++){ if(a[j]>a[j+1]){ t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for(i=0;i<n;i++){ cout<<a[i]<<" "; } }
Python :
def qiuHe(n): s = 0 while n != 0: s = s + n % 10; n = n // 10; return s; n=int(input()) l1=list(map(int,input().split())) l2=[] # for l in l1: # //l2.append(qiuHe(l)); for i in range(0,len(l1)): l1[i] = qiuHe(l1[i]); l1.sort(); for x in l1: print(x,end=' ')
- 1
信息
- ID
- 2086
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 2
- 标签
- 递交数
- 44
- 已通过
- 27
- 上传者