东北林业的作业

数组和字符串

题目号码知识点
7150字符串按ASC2码由小到大输出
7090用字符串接受然后相乘
7089各英文小写字母出现的次数

7150

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//字符串排序
void sort(char **pp,int n)//**pp等效于*p[]
{
	char tmp[100];
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(strcmp(pp[i],pp[j])>0)
			{
				strcpy(tmp,pp[i]);
				strcpy(pp[i],pp[j]);
				strcpy(pp[j],tmp);
			}
}
void output(char *p[],int n)
{
	for(int i=0;i<n;i++)
		printf("%s\n",p[i]); 
}
int main()
{
	void sort1(char **pp,int n);
    void output1(char *p[],int n);
    char str[50],*cp[20];//cp为char指针数组,
    int n;
	while(~scanf("%d\n",&n))
	{
		for(int i=0;i<n;i++)
		{
			gets(str);
			int len=strlen(str);
			cp[i]=(char*)malloc(len*sizeof(char));//动态开辟内存
			strcpy(cp[i],str);
		}
		sort(cp,n);
        output(cp,n);
	}
	return 0;
} 

7090

#include<stdio.h>
#include<string.h>

#define N 100
char a[N],b[N];
int A[N],B[N],t[N],C[N];
int main()
{
	scanf("%s%s",a,b);
	int la=strlen(a);
	int lb=strlen(b);
	for(int i=0;i<la;i++)A[i]=a[la-i-1]-'0';//字符串转数字并逆序
	for(int i=0;i<lb;i++)B[i]=b[lb-i-1]-'0';
	
	for(int i=0;i<lb;i++)
		for(int j=0;j<la;j++)
			C[i+j]+=B[i]*A[j];//先乘起来
	for(int i=0;i<=la+lb+1;i++)//同一处理进位
		if(C[i]>=10)
		{
			C[i+1]+=C[i]/10;
			C[i]%=10;
		}
		
	int lc=N;
	while(C[lc]==0&&lc>=1)lc--;//去除前导0
	for(int i=lc;i>=0;i--)printf("%d",C[i]);//逆序输出
	
	return 0;
}

7089

#include<stdio.h>
#define N 105
char str[N];
int tj[30];
int main()
{
    while(~scanf("%s",str))
    {
        memset(tj,0,sizeof tj);
    	for(int i=0;str[i];i++)
		if(str[i]>='a'&&str[i]<='z')
			tj[str[i]-'a']++;
	
		for(int i=0;i<26;i++)
			if(tj[i])printf("%c  %d\n",'a'+i,tj[i]);	
	}
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值