电子学会二级-字符数组

电子学会二级-字符数组
【深基6.例1】自动修正
https://www.luogu.com.cn/problem/P5733

#include<bits/stdc++.h>
using namespace std;

const int maxn=105;
char s[maxn];
int main(){
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++){
		if(s[i]>='a' && s[i]<='z'){
//			s[i]=toupper(s[i]);
			s[i]=s[i]-'a'+'A';
		}
	}
	printf("%s",s);
	return 0;
}

凯撒密码
https://www.luogu.com.cn/problem/P1914

#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
int n;
char s[maxn];
int main(){
	scanf("%d",&n);
	scanf("%s",&s);
	for(int i=0;i<strlen(s);i++){
		s[i]=(s[i]+n-'a')%26+'a';//超过26 重新开始 
	}
	printf("%s",s);
}

[NOIP2008 提高组] 笨小猴
https://www.luogu.com.cn/problem/P1125

#include<bits/stdc++.h>
using namespace std;

char s[105];
int cnts[26];
int maxn,minn=0x3f3f3f3f;

bool is_prime(int n){
	if(n==0 || n==1){
		return false;
	}
	bool flag=true;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			flag=false;
			break;
		}
	}
	return flag;
}

int main(){
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++){
		cnts[s[i]-'a']++;
	}
	for(int i=0;i<=26;i++){
		if(cnts[i]==0) continue;
		if(maxn<cnts[i]){
			maxn=cnts[i];
		}
		
		if(minn>cnts[i]){
			minn=cnts[i];
		}
	}
//	cout<<maxn<<" "<<minn<<endl;
	if(is_prime(maxn-minn)){
		printf("Lucky Word\n%d",maxn-minn);
	}else{
		printf("No Answer\n0");
	}
} 

口算练习题
https://www.luogu.com.cn/problem/P1957

#include<bits/stdc++.h>
using namespace std;

int n,a,b,c;
char s[50],ans[50],last;
int main(){
	scanf("%d\n",&n);
	for(int i=0;i<n;i++){
		fgets(s,sizeof(s),stdin);
		if(s[0]=='a' || s[0]=='b' || s[0]=='c'){
			last=s[0];
			s[0]=' ';
		}
		sscanf(s,"%d %d",&a,&b);
		switch(last){
			case 'a': c=a+b; sprintf(ans,"%d+%d=%d",a,b,c); break;
			case 'b': c=a-b; sprintf(ans,"%d-%d=%d",a,b,c); break;
			case 'c': c=a*b; sprintf(ans,"%d*%d=%d",a,b,c); break;
		}
		printf("%s\n%d\n",ans,strlen(ans));
	}
	
}
posted @ 2022-06-04 12:13  new-code  阅读(25)  评论(0编辑  收藏  举报