全部评论
题一样吗
楼主我跟你一样
输入要while(getline())
scan.nex()过了33.4% , 改成scan.nextLine()过了66.7%
88.83%
import re
mail = raw_input()
#mail = "123@hu.123@we.i.com"
pattern_split = re.compile(r"([\w\d\&\=\+\$\,\;\?\/\-\_\.\!\~\*\'\(\)\#]*@[\w\d-]+?\.)")
pattern = re.compile(r"([\w\d\&\=\+\$\,\;\?\/\-\_\.\!\~\*\'\(\)\#]*)@([\w\d-]+?)\.")
res = ""
for item in pattern_split.split(mail):
match = pattern.match(item)
if match:
g1 = match.group(1)
g2 = match.group(2)
if len(g2) <= 119 and len(g1) >= 3:
res += (g1[:-3:] + "***" +"@"+g2+".")
else:
res += item
else:
res += item
print res
直接把输入输出就过了50%了。。。 然后这样过了,别人的代码
今天不是硬件、芯片、结构类的最后一场机试么?难道也有软件类的?
楼下第2题多少
#include <string>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define pb push_back
#define mp make_pair
#define maxn 111
#define DEBUG
bool fl[2222];
bool used[2222];
int main() {
string s;
while (getline(cin, s)) {
memset(used, false, sizeof(used));
memset(fl, true, sizeof(fl));
int len = s.length();
bool pre = false;
string ans = "";
for (int i = 0; i < len; ++i) {
if (s[i] == '@') {
int st = i + 1;
// check 119 characters
while (st < len && s[st] != '.' && s[st] !='@' &&
(isdigit(s[st]) || s[st] == '-' || isalpha(s[st]))) st++;
if (st == len || st - i > 119 || s[st] != '.') continue;
int last = st;
// check if >=3 characters
st = i - 1;
while (i - st < 4 && st >= 0 && !used[st] && s[st] != '@' &&
(isdigit(s[st]) || isalpha(s[st]) || s[st] == '&' || s[st] == '=' ||
s[st] == '+' || s[st] == '$' || s[st] == ',' || s[st] == ';' ||
s[st] == '?' || s[st] == '/' || s[st] == '-' || s[st] == '_' ||
s[st] == '.' || s[st] == '!' || s[st] == '~' || s[st] == '*' ||
s[st] == '\'' || s[st] == '(' || s[st] == ')' || s[st] == '#')) st--;
if (i - st == 4) {
for (int j = st + 1; j < i; ++j) {
fl[j] = false;
}
for (int j = i + 1; j <= last; ++j) used[j] = true;
}
}
}
for (int i = 0; i < len; ++i) {
cout << (fl[i] ? s[i] : '*');
}
cout << endl;
}
return 0;
}
#define _CRT_SECURE_NO_WARNINGS #include <vector> #include <iostream> #include<string> using namespace std; bool isE(char t){ if((t>='a'&&t<='z')||(t>='A'&&t<='Z')) return true; return false; } bool isN(char t){ if((t>='0')&&(t<='9')) return true; return false; } bool isS(char t){ if(t=='&')return true; if(t=='=')return true; if(t=='+')return true; if(t=='$')return true; if(t==',')return true; if(t==';')return true; if(t=='?')return true; if(t=='/')return true; if(t=='-')return true; if(t=='_')return true; if(t=='.')return true; if(t=='!')return true; if(t=='~')return true; if(t=='*')return true; if(t=='\'')return true; if(t=='(')return true; if(t==')')return true; if(t=='#')return true; return false; } bool isH(char t){ if(t=='-') return true; return false; } int scanAddress(string& str,int index){ int count=0; while(isE(str[index+count])|isN(str[index+count])|isS(str[index+count])){ count++; } return count; } int scanName(string& str,int index){ int count=0; while(isE(str[index+count])|isN(str[index+count])|isH(str[index+count])){ count++; } return count; } void fake(string& str,int index){ str[index-1]='*'; str[index-2]='*'; str[index-3]='*'; } void fakeCore(string& str,int index,int length){ if(index>length-1) return; int count1=scanAddress(str,index); if(str[index+count1]=='@'&&count1>=3){ int count2=scanName(str,index+count1+1); if(str[index+count1+count2+1]=='.'&&count2<=119) fake(str,index+count1); fakeCore(str,index+count1+count2+2,length); }else{ fakeCore(str,index+count1+1,length); } } int main() { #if 1 freopen("in.txt", "r", stdin); #endif //input string str; getline(cin,str); //fakeCore fakeCore(str,0,str.size()); //output cout<<str; }
#include <bits/stdc++.h> using namespace std; /* int main(){ string mail; set<char> sp; string sps("&=+$,;?/-_.!~*'()#"); for(auto ch:sps) sp.insert(ch); while(getline(cin, mail)){ vector<int> idx; vector<int> node(1, -1); for(int i=0; i<mail.size(); ++i){ if(mail[i] == '@') { idx.push_back(i); for(int j=i+1; j<mail.size(); ++j) { if(mail[j] == '.') {node.push_back(j); break;} if(mail[j] == '@') {node.push_back(i); break;} } } } int flag = false; int old = -1; for(int i=0; i<idx.size(); ++i){ if(!flag){ if(idx[i]-old >= 4 && node[i+1]-idx[i]-1 <= 119 && node[i+1]-idx[i] > 1){ for(int k=idx[i]-1; k>=idx[i]-3; --k){ if(!isalnum(mail[k]) && sp.find(mail[k]) == sp.end()){ goto next; } } for(int k=idx[i]+1; k<node[i+1]; ++k){ if(!isalnum(mail[k]) && mail[k] != '-'){ goto next; } } for(int k=idx[i]-1; k>=idx[i]-3; --k){ mail[k] = '*'; } flag = true; } } else{ if(idx[i]-node[i] >= 4 && node[i+1]-idx[i]-1 <= 119 && node[i+1]-idx[i] > 1){ for(int k=idx[i]-1; k>=idx[i]-3; --k){ if(!isalnum(mail[k]) && sp.find(mail[k]) == sp.end()){ flag = false; goto next; } } for(int k=idx[i]+1; k<node[i+1]; ++k){ if(!isalnum(mail[k]) && mail[k] != '-'){ flag = false; goto next; } } for(int k=idx[i]-1; k>=idx[i]-3; --k){ mail[k] = '*'; } } else{ flag = false; } } next: old = idx[i]; } cout << mail << endl; } }*/
能公布一下题目吗?
相关推荐
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
深信服
| 校招
| 14个岗位
点赞 评论 收藏
分享
![](https://static.nowcoder.com/fe/file/oss/1716965564844UEBJN.png)
![](https://static.nowcoder.com/fe/file/oss/1716965585666UBBME.png)
深信服
| 校招
| 14个岗位
点赞 评论 收藏
分享