【入门5】字符串(今天刷洛谷了嘛)

几道纯模拟题没有写,暂且先放一下

P5733

【深基6.例1】自动修正 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[N];
int main()
{
	cin>>s;
	int n = strlen(s);
	for(int i = 1;i<n;i++)
	{
		if(s[i]>='a'&&s[i]<='z')
		s[i] = char(s[i]-32);
	}
	cout<<s<<"\n";
}

P1914

小书童——凯撒密码 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[N];
int main()
{
	ios;
	//cout<<int('a');//97
	//cout<<int('z');//122
	int n;
	cin>>n;
	cin>>s;
	int num = strlen(s);
	for(int i = 0;i<num;i++)
	{
		int t = (int) s[i] - 'a';//0~25
		t = (t+n)%26;
		s[i] = char((int)'a'+t);
	}
	cout<<s<<"\n";
}

P1125

[NOIP2008 提高组] 笨小猴 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[109];
int ad[30];
int main()
{
	ios;
	cin>>s;
	int n = strlen(s);
	for(int i = 0;i<n;i++)
	{
		ad[s[i]-'a']++;
	}
	sort(ad,ad+26);
	int mn = 0;
	for(int i = 1;i<25;i++)
	{
		if(ad[i])
		{
			mn = ad[i];
			break;
		}
	}
	int ans = ad[25] - mn; 
	bool flag = 1;
	for(int i = 2;i*i<=ans;i++)
	{
		if(ans%i==0)
		{
			flag = 0;
			break;
		}
	}
	if(ans < 2)	flag = 0;
	if(flag)	cout<<"Lucky Word"<<"\n";
	else	cout<<"No Answer"<<"\n";
	if(flag)	cout<<ans<<endl;
	else
	cout<<0<<"\n";
}

P1957

口算练习题 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
int main()
{
	ios;
	int t;
	cin>>t;	
	char op;
	while(t--)
	{
		char s[10];
		cin>>s;
		int a = 0,b;
		if(s[0]>='0'&&s[0]<='9')
		{
			cin>>b;
			int n = strlen(s);
			int p = 1;
			for(int i = n-1;i>=0;i--)
			{
				a += (s[i]-'0')*p;
				p*=10;
			}
		}
		else
		{
			op = s[0];
			cin>>a>>b;
		}
		
		int num = 0;
		if(a<10&&a>=0)	num+=1;
		else if(a<100&&a>=10)	num+=2;
		else if(a<1000&&a>=100)		num+=3;
		else	num+=4;
		
		if(b<10&&b>=0)	num+=1;
		else if(b<100&&b>=10)	num+=2;
		else if(b<1000&&b>=100)		num+=3;
		else	num+=4;
		int ans;
		if(op=='a')	ans = a+b;
		else if(op=='b')	ans = a-b;
		else if(op=='c')	ans = a*b;
		if(ans<0)	num+=3;
		else	num+=2;
		
		cout<<a;
		
		if(op=='a')	cout<<'+';
		else if(op=='b')	cout<<'-';
		else	cout<<'*';
		cout<<b<<'='<<ans<<"\n";
		if(ans<0)
		{
			ans = -ans;
		}
		if(ans == 0)
		num++;
		while(ans)
		{
			num++;
			ans/=10;
		}
		cout<<num<<"\n";
	}
	
}

P5015

[NOIP2018 普及组] 标题统计 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[20];
int main()
{
	cin.getline(s,20);
	int n = strlen(s);
	int ans = 0;
	for(int i = 0;i<n;i++)
	if(s[i]!=' '&&s[i]!='\n')
	ans++;
	cout<<ans<<"\n";
}

P1308

[NOIP2011 普及组] 统计单词数 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
int main()
{
	string a,b;
	getline(cin,a);
	getline(cin,b);
	for(int i = 0;i<a.size();i++)
	a[i] = tolower(a[i]);
	for(int i = 0;i<b.size();i++)
	b[i] = tolower(b[i]);
	a =' '+a+' ';
	b =' '+b+' ';
	if(b.find(a)==string::npos)
	{
		cout<<-1<<"\n";
	}
	else
	{
		int first = b.find(a);
		int q = b.find(a);
		int sum = 0;
		while(q!=string::npos)
		{
			sum++;
			q = b.find(a,q+1);
		}
		cout<<sum<<' '<<first<<"\n";
	}
}

P1765

手机 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
int main()
{
	string s;
	getline(cin,s);
	int ans = 0;
	for(int i = 0;i<s.size()-1;i++)
	{
		if(s[i]==' ')
		ans++;
		else if(s[i]=='a'||s[i]=='d'||s[i]=='g'
		||s[i]=='j'||s[i]=='m'||s[i]=='p'||
		s[i]=='t'||s[i]=='w')
		ans++;
		
		else if(s[i]=='b'||s[i]=='e'||s[i]=='h'
		||s[i]=='k'||s[i]=='n'||s[i]=='q'||
		s[i]=='u'||s[i]=='x')
		ans+=2;
		
		else if(s[i]=='c'||s[i]=='f'||s[i]=='i'
		||s[i]=='l'||s[i]=='o'||s[i]=='r'||
		s[i]=='v'||s[i]=='y')
		ans+=3;
		else
		ans+=4;
	}
	cout<<ans<<"\n";
}

P3741

honoka的键盘 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[109];
int main()
{
	ios;
	int n;
	cin>>n;
	cin>>s;
	int ans = 0;
	for(int i = 0;i<n-1;i++)
	{
		if(s[i]=='V'&&s[i+1]=='K')
		ans++,s[i]='&',s[i+1]='&',i++;
	}
	for(int i = 0;i<n-1;i++)
	{
		if(s[i]==s[i+1]&&s[i]!='&')
		{
			ans++;
			break;
		}
	}
	cout<<ans<<"\n";
}

P1321

单词覆盖还原 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[260];
int main()
{
	cin>>s;
	int n = strlen(s);
	int a = 0,b = 0;
	for(int i = 0;i<n;i++)
	{
		if(s[i]=='b'||s[i+1]=='o'||s[i+2]=='y')
		a++;
		if(s[i]=='g'||s[i+1]=='i'||s[i+2]=='r'||s[i+3]=='l')
		b++;
	}
	cout<<a<<"\n"<<b<<"\n";
}

P1200

[USACO1.1]你的飞碟在这儿Your Ride Is Here 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
char s[260];
int main()
{
	string a,b;
	cin>>a>>b;
	ll pr = 1;
	ll hx = 1;
	for(int i = 0;i<a.size();i++)
	hx*=(a[i]-'A'+1);
	for(int i = 0;i<b.size();i++)
	pr*=(b[i]-'A'+1);
	if(pr%47==hx%47)
	cout<<"GO"<<"\n";
	else
	cout<<"STAY"<<"\n";
}

P1598

垂直柱状图 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath> 
#include<vector>
#include <iomanip>
using namespace std;
typedef long long  ll;
const int inf = 0x3f3f3f3f;
#define ios ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
const int N = 1e6+5;
int q[26];
int main()
{
	int t = 4;
	while(t--)
	{
		string s;
		getline(cin,s);
		for(int i = 0;i<s.size();i++)
		{
			if(s[i]>='A'&&s[i]<='Z')
			{
				q[s[i]-'A']++;
			}
		}
	}
	
	int mx = 0;
	for(int i = 0;i<26;i++)
	{
		mx = max(mx,q[i]);
	}
	for(int i = mx;i>=1;i--)
	{
		for(int j = 0;j<26;j++)
		{
			if(q[j]>=i)
			cout<<'*';
			else
			cout<<' '; 
			if(j!=25)
			cout<<' ';	
		}
		cout<<"\n";
	}
	cout<<"A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"<<"\n";
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Joanh_Lan

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

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

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

打赏作者

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

抵扣说明:

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

余额充值