|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Description
给定某整数数组和某一整数b。要求删除数组中可以被b整除的所有元素,同时将该数组各元素按从小到大排序。如果数组元素数值在A到Z的ASCII之间,替换为对应字母。
Input
第一行为数组元素个数 n 和整数 b (1≤n,b≤100)
第二行为数组各个元素ai (1≤ai≤100)
Output
输出仅一行,每个输出数字或字符之后均有空格。
Sample Input 1
6 2
65 1 5 89 7 9
Sample Output 1
1 5 7 9 A Y
- #include"stdio.h"
- int main(void)
- {
- int n,b,i,j,temp;
- scanf("%d%d",&n,&b);//输入第一行,n和b
- int a[n],m=0;
- for(i=0;i<n;i++)//输入n个数,并把不能被b整除的放入数组a中
- {
- scanf("%d",&temp);
- if (temp%b)
- a[m++]=temp;
- }
- for (i=0;i<m;i++)//冒泡排序
- {
- for (j=0;j<m-1;j++)
- {
- if (a[j]>a[j+1])
- {
- temp=a[j];
- a[j]=a[j+1];
- a[j+1]=temp;
- }
- }
- }
- for(i=0;i<m;i++)//输出
- {
- if(a[i]>=65&&a[i]<=90)//若是大写字母,就以%c输出
- printf("%c ",a[i]);
- else //否则输出该数字
- printf("%d ",a[i]);
- }
- return 0;
- }
复制代码
|
|