zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    Luogu P3731 [HAOI2017]新型城市化
    Luogu P3227 [HNOI2013]切糕 最小割
    Luogu P1654 OSU!
    CF235B Let's Play Osu! 期望dp
    Luogu P2057 [SHOI2007]善意的投票
    任意模数NTT学习笔记
    Burnside引理的感性证明
    JLOI2015 城池攻占
    BZOJ2957 楼房重建
    NOI2009 区间
  • 原文地址:https://www.cnblogs.com/winray/p/4098611.html
Copyright © 2011-2022 走看看