e.cpp

来自「ACM训练题解 最新版 共8题 ACM训练题解 最新版 共8题」· C++ 代码 · 共 46 行

CPP
46
字号
// Problem E
// http://acm.uva.es/p/v108/10896.html
// Solution by semiconductor
#include	<cstdio>
#include	<cstring>
#include    <cctype>
#include    <algorithm>

using namespace std;

char buf[100], word[100];
char str[100];

void
Solve(void)
{
	char ans[26];
	int nans = 0;
	for ( int i = 0; i < 26; i++ ) {
		strcpy(str, buf);
		for ( int j = 0; str[j]; j++ ) 
            if ( islower(str[j]) ) str[j] = (str[j] - 'a' + i) % 26 + 'a';
		char *tok, *s = str;
		while ( tok = strtok(s, " \n") ) {
			s = 0;
			if ( strcmp(tok, word) == 0 ) ans[nans++] = (26 - i) % 26 + 'a';
		}
	}
	sort(ans, ans + nans);
	printf("%.*s\n", nans, ans);
}

int
main()
{
	int T;
	scanf("%d", &T);
	fgets(buf, sizeof buf, stdin);
	while ( T-- ) {
		fgets(buf, sizeof buf, stdin);
		scanf("%s", word);
		Solve();
		fgets(buf, sizeof buf, stdin);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?