sgu274:Spam-filter(字符串模拟)
来源:互联网 发布:linux最常用的20个命令 编辑:程序博客网 时间:2024/06/12 22:42
题目大意:
分析:
AC code:
#include <cstdio>#include <cmath>#include <cstdlib>#include <cstring>#include <cctype>#include <algorithm>#include <string>#include <sstream>#include <iostream>#include <map>#include <set>#include <list>#include <stack>#include <queue>#include <vector>#define pb push_back#define mp make_pairtypedef long long LL;typedef double DB;typedef long double LD;using namespace std;bool letter(char c){ if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) return true; return false;}bool symbol(char c){ if(letter(c) || (c >= '0' && c <= '9') || c == '_' || c == '-') return true; return false;}bool word(const string &s){ if(!s.size()) return false; for(int i = 0, sz = s.size(); i < sz; ++i) if(!symbol(s[i])) return false; return true;}bool prefix(const string &s){ if(!s.size()) return false; int p = 0, q, l = s.size(); while((q = s.find_first_of('.', p)) != -1) { if(!word(s.substr(p, q-p))) return false; p = q+1; } if(!word(s.substr(p, l-p))) return false; return true;}bool domain(const string &s){ int l = s.size(); if(l == 2 || l == 3) { for(int i = 0; i < l; ++i) if(!letter(s[i])) return false; return true; } else return false;}bool suffix(const string &s){ if(!s.size()) return false; int p = s.find_last_of('.'); if(p == -1) return false; return prefix(s.substr(0, p))&&domain(s.substr(p+1, s.size()-p-1));}bool check(const string &s){ int p = s.find('@'); if(p == -1 || s.find_first_of('@', p+1) != -1) return false; return prefix(s.substr(0, p))&&suffix(s.substr(p+1, s.size()-p-1));}int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int Test; string input; scanf("%d\n", &Test); while(Test--) { getline(cin, input); if(check(input)) cout << "YES" << endl; else cout << "NO" << endl; } #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu274:Spam-filter(字符串模拟)
- sgu - 274 - Spam-filter(模拟)
- Spam Filter Rules
- Best Free Spam Filter for Experienced Users
- spam
- spam
- poj-1295--- I hate SPAM, but some people love it (模拟)
- 字符串模拟
- 过滤字符串filter
- EditText 字符串过滤 Filter
- Spring filter 字符串过滤器
- bayes spam
- Sicily1133.SPAM
- 什么是Spam
- SEO | SPAM
- Spam Filters
- 1001. SPAM
- 1133. SPAM
- OPENCV Cvsmooth 函数
- DBUtil
- Matlab和C混合编程举例
- 那年的夏天——致毕业
- Solution : Can't quit Packagekit - adding software package in OpenSuse
- sgu274:Spam-filter(字符串模拟)
- C语言实现base64编码
- 黑马day06 jsp之page指令
- 日语学习之沪江N3基础 20150620 -5
- C专家编程》笔记三:第四章 数组和指针并不相同
- M序列
- PCA的数学原理
- 10 responsibility chain
- 明月不知离恨苦,斜光到晓穿朱户