problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
luogu::P1308类 参考

洛谷 P1308 [NOIP2011 普及组] 统计单词数 更多...

#include <luogu.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 

详细描述

洛谷 P1308 [NOIP2011 普及组] 统计单词数

在文件 luogu.h537 行定义.

成员函数说明

◆ main()

int luogu::P1308::main ( istream &  cin,
ostream &  cout 
)
static

在文件 luogu.cpp1970 行定义.

1970 {
1971 int sum = 0;
1972 int pos = -1;
1973 auto *target = new char[11];
1974 auto *article = new char[1000001];
1975 cin.getline(target, 11);
1976 for(int i = 0; i < strlen(target); i++) {
1977 target[i] = tolower(target[i]);
1978 }
1979 cin.getline(article, 1000001);
1980
1981 for(int i = 0; i + strlen(target) <= strlen(article); i++) {
1982 if(!((i == 0 || article[i - 1] == ' ') && (i + strlen(target) == strlen(article) || article[i + strlen(target)] == ' '))) {
1983 continue;
1984 }
1985 bool ok = true;
1986 for(int j = 0; j < strlen(target); j++) {
1987 if(target[j] != tolower(article[i + j])) {
1988 ok = false;
1989 break;
1990 }
1991 }
1992 if(ok) {
1993 sum++;
1994 if(pos == -1) {
1995 pos = i;
1996 }
1997 }
1998 }
1999 if(sum == 0) {
2000 cout << -1;
2001 } else {
2002 cout << sum << " " << pos;
2003 }
2004 delete[] target;
2005 delete[] article;
2006 return 0;
2007 }

被这些函数引用 luogu::TEST().


该类的文档由以下文件生成: