【牛客比赛】小Q喜欢撸串(字符串)

链接:https://ac.nowcoder.com/acm/problem/23905
来源:牛客网

description

小Q挺喜欢撸串的,没错,字符串!

你给小Q送上了n个字符串

对于一个字符串s,如果在小Q撸掉(删除)任意个字符之后,"NowCoder"是其子串,则这个字符串s是可撸的。小Q最近切题切到手软,想撸串散散心。如果你给他呈现的字符串是可撸的,他会很开心,否则他会很桑心。
输入描述:

一个整数n,表示字符串的数量

接下来每行一个字符串sis_isi​,表示小Q看到的第i个字符串

输出描述:

输出有n行,如果小Q开心他会说QAK,否则他会说QIE

示例1
输入

2
​NowCoder
​NoowCoder

输出

QAK
QAK

说明

第一个字符串不需要撸掉任何字符
第二个字符串撸掉第二个或者第三个都可以

示例2
输入

5
​Nowcoder
​nowcoder
​NowCoder
​NowoowCoder
​NOI2019NowCoder

输出

QIE
QIE
QAK
QAK
QAK
分析:

快读,读入字符和整型数字,利用getchar进行读入,因getchar比任何读入方式都快
尽量使用快读或者scanf,以防卡时间

inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x = (x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}

缩短读入数据的时间,从前往后遍历,相同则p++,真想不明白这个思路一开始怎么没想到??这样的题目以前做过不少啊。。。还是要真正理解吧

#include
using namespace std;
const int N = 1e5 + 7;
int n;
char ch[N][107],sss[10]="NowCoder";
inline int read() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x = (x<<3)+(x<<1)+(ch^48); ch=getchar(); }
    return x * f;
}
int main()
{
    n = read();
    for(int i=1;i<=n;++i)
        cin>>ch[i];
    int p,Len;
    for(int i=1;i<=n;++i) {
        p = 0 ,Len = strlen(ch[i]);
        for(int j=0;j

需要掌握:
字符类型二维数组。
eg:char a[n][m]表示n个长度不大于m的字符串,m的大小表示第n个字符串的第m个字符
scanf("%s",a[i]);//输入第i个字符串
char a[3][6]={“tread”,“micrp”,“soft”};
for(int i=0;i<3;i++)
{
printf("%s ",a[i]);//依次输出三个字符串
}
若固定i不变
a[i][j]代表的是第i个字符串的第j个字符

以下是一道题意晦涩其实很简单的题目。

One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k.

There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number ai (1 ≤ ai ≤ n·k). All numbers ai accidentally turned out to be different.

Now the children wonder, how to divide the orange so as to meet these conditions:
each child gets exactly n orange segments;
the i-th child gets the segment with number ai for sure;
no segment goes to two children simultaneously.
Help the children, divide the orange and fulfill the requirements, described above.
Input

The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a1, a2, …, ak (1 ≤ ai ≤ n·k), where ai is the number of the orange segment that the i-th child would like to get.

It is guaranteed that all numbers ai are distinct.
Output

Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.

You can print a child’s segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them.
Examples
Input

2 2
4 1

Output

2 4 
1 3 

Input

3 1
2

Output

3 2 1 

这个代码核心有些类似上一个题,虽然这两个题完全不沾边,但是同为水题,还是要做好朋友的

#include
#include
#include
#include
using namespace std;
int n,ans,k;
int a[100],vis[1000];
int main()
{
	while(cin>>n>>k)
	{
		int num=1;
		memset(vis,0,sizeof(vis));
		for(int i=1;i<=k;i++)scanf("%d",&a[i]),vis[a[i]]=1;
		for(int i=1;i<=k;i++)
		{
			printf("%d",a[i]);
			for(int j=1;j

你可能感兴趣的:(字符串)