12月6日problem

Problem A: 零起点学算法101——统计字母数字等个数

#include<stdio.h>
#include<string.h>
int main()
{
	char str1[120];
	while(gets(str1)) 
	{
		int n=0,m=0,q=0,p=0,i,x;
		x=strlen(str1);
		for(i=0;i<x;i++)
		{
			if(str1[i]>='A' &&str1[i]<='Z')
			{
				n++;
			}else if(str1[i]>='a'&&str1[i]<='z')
			{
				n++;
			}else if(str1[i]>='0' && str1[i]<='9')
			{
				m++;
			}else if(str1[i]==' ')
			{
				q++;
			}else
			{
				p++;
			}
		}
		printf("%d %d %d %d\n",n,m,q,p);
	}
}

Problem B: 零起点学算法107——统计元音

#include<stdio.h>
#include<string.h>
int main()
{
	char s[120];
	int n;
	scanf("%d",&n);
	getchar();
	while(n>0) 
	{
		gets(s);
		int x=strlen(s),j,a=0,e=0,i=0,o=0,u=0;
		for(j=0;j<x;j++)
		{
			if(s[j]=='a') a++;
			if(s[j]=='e') e++;
			if(s[j]=='i') i++;
			if(s[j]=='o') o++;
			if(s[j]=='u') u++;
		}
		n--;
		printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d",a,e,i,o,u);
		if(n>0) printf("\n\n");
	}
}

Problem C: 零起点学算法105——C语言合法标识符

#include<stdio.h>
#include<string.h> 
char a[100];
int main()
{
	int n;
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		gets(a);
		int x=strlen(a),i;
		for(i=1;i<x;i++)
		{
			if(!((a[i]>='a'&&a[i]<='z') || (a[i]>='A'&&a[i]<='Z')||(a[i]=='_')||(a[i]>='0'&&a[i]<='9'))) break;
		}
		if(!((a[0]>='a'&&a[0]<='z')||(a[0]>='A'&&a[0]<='Z')||(a[0]=='_'))) i=0;
		if(i==x)printf("yes");
		else printf("no");
		if(n>0)printf("\n");
	}
	return 0;
} 

Problem D: 杨辉三角

#include<stdio.h>
int main()
{
	int n,m;
	while(scanf("%d",&n)!=EOF)
	{
		int a[n][n],i,j;
		for(i=0;i<n;i++)
		{
			printf("1");
			a[i][0]=1;
			a[i][i]=1;
			for(j=1;j<i;j++)
			{
				a[i][j]=a[i-1][j]+a[i-1][j-1];
				printf(" %d",a[i][j]);
			}
			if(i!=0) printf(" 1");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Problem E: 求和

#include<stdio.h>
int main()
{
	int n,m,i,j;
	scanf("%d",&n);
	int a[n+10];
	for(i=0;i<n;i++)
	{
		int k=0,sum=0;
		scanf("%d",&m);
		for(j=1;j<=m;j++)
		{
			k+=j;
			sum+=k*j;
		}
		a[i]=sum;
	}
	for(i=0;i<n-1;i++)
	{
		printf("%d\n",a[i]);
	}
	printf("%d",a[i]);
}

Problem F: 十六进制转十进制

#include<stdio.h>
#include<string.h>
char a[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'} ;
long long b;
char c[10000];
int main()
{
	int m,r,x,j=0,i;
	while(gets(c))
	{
		b=0;
		x=strlen(c);
		for(i=0;i<x;i++) 
		{
			int flag=0;
			for(j=0;j<16;j++)
			{
				if(c[i]==a[j])
				{
					flag=1;
					break;
				}
			}
			if(flag) b=b*16+j;
		}
		printf("%lld\n",b);
		
	}
}

Problem G: 含数字5的个数

#include<stdio.h>
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int k=0,y;
		while(n>0)
		{
			y=n%10;
			if(y==5) k++;
			n/=10;
		}
		printf("%d\n",k);
	}
	return 0;
} 

Problem H: 统计各种字符个数

#include<stdio.h>
#include<string.h>
int main()
{
	char str1[120];
	gets(str1);
	
		int n=0,m=0,q=0,p=0,i,x;
		x=strlen(str1);
		for(i=0;i<x;i++)
		{
			if(str1[i]>='A' &&str1[i]<='Z')
			{
				n++;
			}else if(str1[i]>='a'&&str1[i]<='z')
			{
				n++;
			}else if(str1[i]>='0' && str1[i]<='9')
			{
				m++;
			}else if(str1[i]==' ')
			{
				q++;
			}else
			{
				p++;
			}
		}
		printf("charaters: %d\nblanks: %d\ndigitals: %d\nothers: %d",n,q,m,p);
	
}

Problem I: 统计每个字母个数

#include<stdio.h>
#include<string.h> 
char a[100];
int b[26];
int main()
{
	while(gets(a))
	{
		int x=strlen(a),i;
		for(i=0;i<26;i++) b[i]=0;
		for(i=0;i<x;i++)
		{
			if(a[i]>='a'&&a[i]<='z')
			{
				b[a[i]-'a']++;
			}else if(a[i]>='A'&&a[i]<='Z')
			{
				b[a[i]-'A']++;
			}
		}
		for(i=0;i<26;i++)
		{
			if(b[i]>0)
			{
				printf("%c: %d\n",i+'a',b[i]);
			}
		}
		printf("\n");
	}
	return 0;
} 

Problem J: 判断回文字符串

#include<stdio.h>
#include<string.h>
int pd(char s[],int i,int j)
{
	while(i<j)
	{
		if(s[i]==s[j])
		{
			i++;j--;
		}else
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	char s[120];
	while(gets(s)) 
	{
		int x=strlen(s),j=x-1,i=0;
		if(pd(s,i,j)==1)
		{
			printf("Yes\n");
		}else
		{
			printf("No\n");
		}
	}
}

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值