洛谷字符串几题C

P3741 honoka的键盘

#include<stdio.h> 
int main()
{
	int i, j, len, count=0, max = 0;
	char s[105];
	scanf("%d", &len);
	scanf("%s", s);
	for (j = 0; j < len - 1; j++) {
		if (s[j] == 'V' && s[j + 1] == 'K')
			count++;
	}
	if (count > max) max = count;
	
	for (i = 0; i < len; i++) {
		if (s[i] == 'V') s[i] = 'K';
		else if (s[i] == 'K') s[i] = 'V';
		count=0;
		for (j = 0; j < len - 1; j++) {
			if (s[j] == 'V' && s[j + 1] == 'K')
				count++;
		}
		if (count > max) max = count;
		
		//要改回来!找这个错误找了好久(伤心——) 
		if (s[i] == 'V') s[i] = 'K';
		else if (s[i] == 'K') s[i] = 'V';
		}
	printf("%d",max);
	return 0;
}

P1914 小书童——凯撒密码

#include<stdio.h>
#include<string.h>
char move(char *a,int n)
{
	for(int i=0;a[i]!='\0';i++)
	{
		a[i]=((a[i]-'a')+n)%26+'a';
	}
}

int main()
{
	int n;		
	scanf("%d",&n);
	char a[55];	
	scanf("%s",a);
	move(a,n);
	puts(a);
	return 0;
 } 

P1765 手机 

#include<stdio.h>

int main()
{
	int count=0,i;
	char a[205];
	gets(a);
	for(i=0;a[i]!='\0';i++)
	{
		if(a[i]=='a'||a[i]=='d'||a[i]=='g'||a[i]=='j'||a[i]=='m'||a[i]=='p'||a[i]=='t'||a[i]=='w'||a[i]==' ') 
			count+=1;
		if(a[i]=='b'||a[i]=='e'||a[i]=='h'||a[i]=='k'||a[i]=='n'||a[i]=='q'||a[i]=='u'||a[i]=='x') 
			count+=2;
		if(a[i]=='c'||a[i]=='f'||a[i]=='i'||a[i]=='l'||a[i]=='o'||a[i]=='r'||a[i]=='v'||a[i]=='y') 
			count+=3;
		if(a[i]=='s'||a[i]=='z') 
			count+=4;
	}
	printf("%d",count);
	return 0;
}
//在题解区看到了很多解题思路
#include<stdio.h>
#include<string.h>

int main()
{
	int count=0;
	int i=0;
	char a[205];
	gets(a);
	char t1[15]="adgjmptw ",t2[15]="behknqux",t3[15]="cfilorvy",t4[5]="sz";
	while(a[i]!='\0')
	{
		if(strchr(t1,a[i])) count++;
		else if(strchr(t2,a[i])) count+=2;
		else if(strchr(t3,a[i])) count+=3;
		else if(strchr(t4,a[i])) count+=4;
		i++;
	}
	printf("%d",count);
	return 0;
}
#include<stdio.h>

int form[35]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4};
int main()
{
	int count=0;
	char a[105];
	gets(a);
	for(int i=0;a[i]!='\0';i++)
	{
		if(a[i]==' ') count++;
		else count+=form[a[i]-'a'];
	}
	
	printf("%d",count);
	return 0;
}

 P5015

[NOIP2018 普及组] 标题统计

//顺序颠倒
	strcpy(tp,a);
	for(i=0;i<len1;i++){
		a[i]=tp[len1-i-1];
	 } 
#include<stdio.h>
int main()
{
	char a;
	int cnt=0;
	while((a=getchar())!=EOF)// !运算符的优先级高于= 
	{
		if(a==' ') continue;
		else if(a=='\n')  break;
		cnt++;
	}
	printf("%d",cnt);
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值