• Sicily 1133. SPAM


    题目地址:1133. SPAM

    思路:

         题目意思是说在‘@’的前后出现题目给定的合法字符或者不连续出现‘.’字符的话,这个就是合理的输出。

         那么以@为中心,向前,向后扫描,当扫描到不符合字符时,记录此时位置,以前后为区间,输出字符。

         具体代码如下:

     1 #include <iostream>
     2 #include <string>
     3 using namespace std;
     4 
     5 bool is_ok(char ch) {
     6     if ((ch >= 'A'&&ch <= 'Z') || (ch >= 'a'&&ch <= 'z') ||
     7         (ch >= '0'&&ch <= '9') || ch == '-'||ch == '_') {
     8            return true;
     9     }
    10     return false;
    11 }
    12 
    13 int main() {
    14     string test;
    15     while (getline(cin, test)) {
    16         if (test.size() == 0) continue;
    17         for (int i = 1; i < test.size()-1; i++) {
    18             if (test[i] == '@'&&is_ok(test[i-1])&&is_ok(test[i+1])) {
    19                 int begin, end;
    20                 for (begin = i-1; begin >= 0; begin--) {
    21                     if ((test[begin] == '.'&&test[begin+1] == '.')) {
    22                         break;
    23                     }
    24                     if (test[begin] != '.'&&!is_ok(test[begin])) {
    25                         break;
    26                     }
    27                 }
    28                 if (test[begin+1] == '.') begin++;
    29                 for (end = i+1; end < test.size(); end++) {
    30                     if ((test[end] == '.'&&test[end-1] == '.')) {
    31                         break;
    32                     }
    33                     if (test[end] != '.'&&!is_ok(test[end])) {
    34                         break;
    35                     }
    36                 }
    37                 if (test[end-1] == '.') end--;
    38                 for (int j = begin+1; j <= end-1; j++) {
    39                     cout << test[j];
    40                 }
    41                 cout << endl;
    42             }
    43         }
    44      }
    45     
    46     return 0;
    47 }
  • 相关阅读:
    魔术方法___toString()
    魔术方法__set()
    魔术方法__get()
    php面向对象之final关键字用法及实例
    php面向对象之什么是抽象类?及抽象类的作用
    php面向对象之对象克隆方法
    php面向对象之对象比较用法详解
    php面向对象之instanceof关键字的用法
    php表单怎么提交到数据库?
    php表单的验证详解
  • 原文地址:https://www.cnblogs.com/winray/p/4098611.html
Copyright © 2020-2023  润新知