1 条题解
-
0
C :
#include<stdio.h> int paixu(int*a,int n); main() { int n,b,i; scanf("%d %d",&n,&b); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); } paixu(a,n); for(i=0;i<n;i++) { if(a[i]%b!=0) { if(a[i]>=65&&a[i]<=90) { printf("%c ",a[i]); } else printf("%d ",a[i]); } } } int paixu(int*a,int n) { int i,j,t=0; for(i=0;i<n-1;i++) { for(j=0;j<n-1-i;j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } }
C++ :
#include<bits/stdc++.h> using namespace std; int a[101]; int f[101]; int main(){ int n,b,i,k; cin>>n>>b; for(i=1;i<=n;i++){ cin>>a[i]; } //从a数组中寻找b的倍数,如果不是b的倍数存入f数组 k = 0; for(i=1;i<=n;i++){ if(a[i]%b!=0){ k++; f[k] = a[i]; } } //默认从小到大排序 sort(f+1,f+1+k); for(i=1;i<=k;i++){ if(f[i]>=65 && f[i]<=90) { cout<<char(f[i])<<" "; }else{ cout<<f[i]<<" "; } } return 0; }
Java :
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { int n = scanner.nextInt(); int b = scanner.nextInt(); List<Integer> nums = new ArrayList<>(); for (int i = 0; i < n; i++) { int temp = scanner.nextInt(); if (temp % b != 0) { nums.add(temp); } } Collections.sort(nums); for (int i = 0; i < nums.size(); i++) { if (nums.get(i) >= 'A' && nums.get(i) <= 'Z') { int temp = nums.get(i); char ch = (char) temp; System.out.print(ch); } else { System.out.print(nums.get(i)); } System.out.print(i == nums.size() - 1 ? "\r\n" : " "); } } } }
Python :
n,m=list(map(int,input().split())) list1=list(map(int,input().split())) list2=[] for item in list1: if item%m!=0: list2.append(item) list2.sort() for item in list2: if ord('A')<=item<=ord('Z'): print(chr(item),end=" ") else: print(item,end=" ")
- 1
信息
- ID
- 2728
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者