Coderforces 字符串水题合集

今天我们聊聊 Coderforces 字符串水题合集。

字符串就是string。

这是string的百度翻译,我们要谈的是画框的。↓

string是C++、javaVB等编程语言中的字符串,字符串是一个特殊的对象,属于引用类型。 在javaC#中,String类对象创建后,字符串一旦初始化就不能更改,因为string类中所有字符串都是常量,数据是无法更改,由于string对象的不可变,所以可以共享。对String类的任何改变,都是返回一个新的String类对象。 C++标准库中string类以类型的形式对字符串进行封装,且包含了字符序列的处理操作。【 本词条由“科普中国”科学百科词条编写与应用工作项目 审核 】

Codeforces是一家为计算机编程爱好者提供在线评测系统的俄罗斯网站。该网站由萨拉托夫国立大学的一个团体创立并负责运营。

不管学字符(char)还是字符串(string),都要学ASCLL码,如下图:

那好,给你做几道判断题:

1.Codeforces简称cf,是美国主办的。( )

2.string在编程中是弦乐器的意思。 ( )

3.水题指的是狂简单的题。 ( )

参考答案:1.✘ 2.✘ 3.✔

目录

96A - Football

837A - Text Volume

118A - String Task

1105B - Zuhair and Strings

133A - HQ9+

1674B - Dictionary

236A - Boy or Girl

745A - Hongcow Learns the Cyclic Shift


96A - Football

题目描述:

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Petya loves football very much. One day, as he was watching a football match, he was writing the players’ current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.

Input
The first input line contains a non-empty string consisting of characters “0” and “1”, which represents players. The length of the string does not exceed 100 characters. There’s at least one player from each team present on the field.

Output
Print “YES” if the situation is dangerous. Otherwise, print “NO”.

Examples
input
001001
output
NO
input
1000000001
output
YES

题目大意:

题意很简单,及输入一个字符串,输出是否有连续7位都是0或都是1。

题目思路:

从0循环到s.size()-7,依次用substr函数取子串。

substr函数在oracle中使用表示被截取的字符串或字符串表达式。和instr()函数不同,instr()函数是要截取的字符串在源字符串中的“位置”,substr()函数是截取字符串的“内容”。

子串,计算机术语,串中任意个连续的字符组成的子序列称为该串的子串。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s; cin>>s;
	for(int i=0;i<=int(s.size()-7);i++){
		string t=s.substr(i,7);
		if(t=="0000000"||t=="1111111"){
	        cout<<"YES";
			return 0; 	
	    }
	}
	cout<<"NO";
	return 0;   
}

837A - Text Volume

题目描述:

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a text of single-space separated words, consisting of small and capital Latin letters.

Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.

Calculate the volume of the given text.

Input
The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text.

The second line contains text of single-space separated words s1, s2, …, si, consisting only of small and capital Latin letters.

Output
Print one integer number — volume of text.

Examples
Input
7
NonZERO
Output
5
Input
24
this is zero answer text
Output
0
Input
24
Harbour Space University
Output
1
Note
In the first example there is only one word, there are 5 capital letters in it.

In the second example all of the words contain 0 capital letters.

题目大意:

输入一个数n,在输入n个字符(包含空格),每个空格隔开两个单词,输出一个单词最多有多少个大写字母。

题目思路:

getline函数输入,注意要加getchar函数读入换行(\n),依次用max函数取最大值。

getline是C++标准库函数;但不是C标准库函数,而是POSIX(IEEE Std 1003.1-2008版本及以上)所定义的标准库函数(在POSIX IEEE Std 1003.1-2008标准出来之前,则只是GNU扩展库里的函数)。getline会生成一个包含一串从输入流读入的字符的字符串,直到以下情况发生会导致生成的此字符串结束:1)到文件结束,2)遇到函数的定界符,3)输入达到最大限度。

getchar是读入函数的一种。它从标准输入里读取下一个字符,相当于getc(stdin)。返回类型为int型,为用户输入的ASCII码

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值