QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765448#9578. 爱上字典forget-star#Compile Error//C++141.5kb2024-11-20 14:19:172024-11-20 14:19:18

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 14:19:18]
  • 评测
  • [2024-11-20 14:19:17]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long

using namespace std;

int read()
{
	int a = 0,x = 1;char ch = getchar();
	while(ch > '9' || ch < '0') {if(ch == '-') x = -1;ch = getchar();}
	while(ch >='0' && ch <= '9') {a = a*10 + ch-'0';ch = getchar();}
	return a*x;
}
const int N = 1e6+7,base1 = 133,base2 = 131,mod1 = 1000429,mod2 = 20190631;
char s[N*5];
int head[N],go[N],nxt[N],cnt,val[N];
void add(int u,int v,int w)
{
	go[++cnt] = v;
	nxt[cnt] = head[u];
	head[u] = cnt;
	val[cnt] = w;
}
int fid(int u,int v)
{
	for(int e = head[u];e;e = nxt[e]) {
		if(go[e] == v) return e;
	}
	return 0;
}
int main()
{
	// freopen("in.in","r",stdin);
	gets(s+1);int len = strlen(s+1);s[len+1] = ' ';len ++;
	ll hash1 = 0,hash2 = 0;
	for(int i = 1;i <= len;i ++) {
		if(s[i] >= 'A' && s[i] <= 'Z') s[i] += 'a'-'A';
		if(s[i] > 'z' || s[i] < 'a') {
			if(hash1) {
				int e = fid(hash1,hash2);
				if(e) val[e] ++;
				else {
					add(hash1,hash2,1);
				}
				hash1 = hash2 = 0;
			}
			continue;
		}
		hash1 = (hash1 * base1 + s[i]) % mod1;
		hash2 = (hash2 * base2 + s[i]) % mod2;
	}
	int n = read();
	for(int i= 1;i <= n;i ++) {
		scanf("%s",s+1);len = strlen(s+1);
		hash1 = hash2 = 0;
		for(int j = 1;j <= len;j ++) {
			hash1 = (hash1 * base1 + s[j]) % mod1;
			hash2 = (hash2 * base2 + s[j]) % mod2;
		}
		int e = fid(hash1,hash2);
		val[e] = 0;
	}
	int ans = 0;
	for(int i = 1;i <= cnt;i ++) ans += val[i];
	printf("%d\n",ans);
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:35:9: error: ‘gets’ was not declared in this scope; did you mean ‘getw’?
   35 |         gets(s+1);int len = strlen(s+1);s[len+1] = ' ';len ++;
      |         ^~~~
      |         getw
answer.code:55:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   55 |                 scanf("%s",s+1);len = strlen(s+1);
      |                 ~~~~~^~~~~~~~~~