基础(字符串)

1163: 【基础】我是第几个单词

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	string str1;
	string str2;
	int num1 = 0;
	int word_number = 1;
	int nearest = 9999;
	int num2 = 0;
	getline(cin, str1);
	getline(cin, str2);
	str2 = " " + str2 ;
	int a = str1.find(str2);
	if (a >= 0)
	{
		for (int i = 0; i < str1.size(); i++)
		{
			if (str1[i] == ' ')
			{
				num2++;
				if (abs(i - a) < nearest)
				{
					nearest = abs(i - a);
					if (nearest == 0)
					{
						break;
					}
				}
			}
		}
		cout << num2 + 1;
	}
	else if (a < 0)
	{
		for (int i = 0; i < str1.size(); i++)
		{
			if ((str1[i] > 64 && str1[i] < 91) || (str1[i] > 96 && str1[i] < 123))//ASCII码中字母对应的值
			{
				num1++;
			}
		}
		cout << num1;
	}
	return 0;
}

1332: 贝贝的车牌问题

#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,n=0;
	string s;
	cin>>N;
	for(int i=1;i<=3;i++){
		cin>>s;
		if(s[0]>=65&&s[0]<=71||s[0]>=82&&s[0]<=84){
			n+=1;
		}
	}
	cout<<N-n;
}

1397: 【入门】请输出n行的9*9乘法表

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i==1){
            cout<<"1*1=1"<<endl;
        }
        if(i==2){
            cout<<"2*1=2 2*2=4"<<endl;
        }
        if(i==3){
            cout<<"3*1=3 3*2=6 3*3=9"<<endl;
        }
        if(i==4){
            cout<<"4*1=4 4*2=8 4*3=12 4*4=16"<<endl;
        }
        if(i==5){
            cout<<"5*1=5 5*2=10 5*3=15 5*4=20 5*5=25"<<endl;
        }
        if(i==6){
            cout<<"6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36"<<endl;
        }
        if(i==7){
            cout<<"7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49"<<endl;                    
        }
        if(n>=8){
            cout<<"8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64"<<endl;
        }
        if(n>=9){
            cout<<"9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81"<<endl;
        }
    }
}

1048: 凯撒密码

#include<bits/stdc++.h>
using namespace std;
char a[50];
int main(){
	int n;
	cin>>n>>a;
	for(int i=0;i<strlen(a);i++){
		if(a[i]>='a'&&a[i]<=122-n){
			printf("%c",a[i]+n);
		}
		else{
			printf("%c",a[i]-122+96+n);
		}
	}
} 

1824: 电报文字

#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
    char x[10000];
    int b,d;
    
    gets(x);
int c=strlen(x);

for(d=0;d<c;d++)
 {
   if(x[d]=='z')
   cout<<'a';
    
   else if((x[d]>='a')&&(x[d]<='y'))
  {x[d]+=1; cout<<x[d];}
   
else  { cout<<x[d];}
   
 }

return 0;
}

1271: 倒置输出字符串

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=s.length()-1;i>=0;i--){
		cout<<s[i];
	}
}

1282: 【入门】删除指定字符

#include<stdio.h>
#include<string.h>
int main()
{   int k;
    char str[100],c;
     gets(str);
     c=getchar();             
    k=strlen(str);
    int i,j=0;
    for(i=0;i<k;i++){
        if(str[i]!=c){
            str[j]=str[i];   
            j++;
        }
    }
            str[j]='\0';
    puts(str);
}

1039: 判断字符

n=input()
if n>='a'and n<='z':
    print('lower')
if n>='A'and n<='Z':
    print('upper')
if n>=0 and n<=9:
    print('delit')

2432: 自动修正2

#include <bits/stdc++.h>
using namespace std;
int main(){
    char c;
    while(cin>>c){
        if(c>='A'&&c<='Z'){
            printf("%c",c-'A'+'a');
        }
        else{
            cout<<c;
        }
    }
}

1047: 自动修正

#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    for(int i=0;i<s.length();i++){
        if(s[i]>='a'&&s[i]<='z'){
            printf("%c",s[i]-'a'+'A');
        }
        else{
            printf("%c",s[i]);
        }
    }
}

1031: 回文

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,a;
	cin>>s;
	if(s.length()%2==0){
		for(int i=0;i<s.length();i++){
			if(s[i]==s[s.length()-1-i]){
				a="TRUE";
			}
			else{
				a="FALSE";
				break;
			}
		}
	}
	else{
		for(int i=0;i<(s.length()-1)/2;i++){
			if(s[i]==s[s.length()-1-i]){
				a="TRUE";
			} 
			else{
				a="FALSE";
				break;
			}
		}
	}
	cout<<a;
}

1062: 三个好朋友

#include<bits/stdc++.h>
using namespace std;
int main(){
	string name1,name2,name3;
	cin>>name1>>name2>>name3;
	cout<<name1+","+name2+" and "+name3+" are good friends";
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Asucceed

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值