USACO Name That Number(水题暴力)
2015-09-30 21:16
423 查看
直接对于字典中的每一个字符串扫描,看看是否等价于输入的数字。 网上有的人做的也太麻烦了。
细节参见代码:
/*
ID: m1785421
LANG: C++
TASK: namenum
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<sstream>
#include<fstream>
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const int maxn = 11;
int n,m;
map<char, int> p;
void init() {
char c = 'A';
for(int i = 2; i <= 9; i++) {
p[c] = i; c++; if(c == 'Q' || c == 'Z') c++;
p[c] = i; c++;if(c == 'Q' || c == 'Z') c++;
p[c] = i; c++;if(c == 'Q' || c == 'Z') c++;
}
}
char s[20];
string dict;
int main() {
freopen("namenum.in","r",stdin);
freopen("namenum.out","w",stdout);
ifstream buf("dict.txt");
init();
scanf("%s",s);
n = strlen(s);
bool flage = false;
while(buf >> dict) {
int len = dict.size();
if(n != len) continue;
bool ok = true;
for(int i = 0; i < len; i++) {
char c = dict[i];
int v = p[c];
int u = s[i] - '0';
if(v != u) { ok = false; break; }
}
if(ok) cout<<dict<<"\n", flage = true;
}
if(!flage) printf("NONE\n");
return 0;
}
细节参见代码:
/*
ID: m1785421
LANG: C++
TASK: namenum
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<sstream>
#include<fstream>
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const int maxn = 11;
int n,m;
map<char, int> p;
void init() {
char c = 'A';
for(int i = 2; i <= 9; i++) {
p[c] = i; c++; if(c == 'Q' || c == 'Z') c++;
p[c] = i; c++;if(c == 'Q' || c == 'Z') c++;
p[c] = i; c++;if(c == 'Q' || c == 'Z') c++;
}
}
char s[20];
string dict;
int main() {
freopen("namenum.in","r",stdin);
freopen("namenum.out","w",stdout);
ifstream buf("dict.txt");
init();
scanf("%s",s);
n = strlen(s);
bool flage = false;
while(buf >> dict) {
int len = dict.size();
if(n != len) continue;
bool ok = true;
for(int i = 0; i < len; i++) {
char c = dict[i];
int v = p[c];
int u = s[i] - '0';
if(v != u) { ok = false; break; }
}
if(ok) cout<<dict<<"\n", flage = true;
}
if(!flage) printf("NONE\n");
return 0;
}
相关文章推荐
- 用fail2ban阻止SSH和VSFTP暴力破解密码
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes