北京师范大学第十五届ACM决赛-重现赛C Captcha Cracker (字符串模拟)

链接:https://ac.nowcoder.com/acm/contest/3/C
来源:牛客网

Captcha Cracker
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
www.02469.com(本网页纯属虚构,如有雷同,纯属巧合),是一个资源丰富的教学资源网站,好学的SK同学经常访问这个网站。通常来说,网站为了安全考虑,登录的时候都需要用户输入验证码,这就让SK同学非常不爽了。

SK同学希望你能帮他写一个程序来自动识别验证码的内容,验证码由小写字母和阿拉伯数字组成,你需要识别出其中所有的0,2,4,6,9以及这5个数字对应的英文单词,并按照它们在验证码中出现的顺序以数字形式输出。

为了表示感谢,SK同学愿意跟你分享他私藏的教学资源。

输入描述:
第一行是一个正整数T(≤ 10),表示测试数据的组数, 每组测试数据只有一行,包含一个长度不超过100000的只由小写字母和阿拉伯数字组成的非空字符串。
输出描述:
对于每组测试数据,输出一行字符串,表示识别出的验证码。
示例1
输入
复制
2
onetwothreefourfiveseven
0two4six6siiiiix
输出
复制
24
02466
说明
0 - zero
2 - two
4 - four
6 - six
9 - nine

题意:

思路:
直接用字符串类string 模拟就好了

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
map<int,string> m;
int main()
{
    //freopen("D:\code\text\input.txt","r",stdin);
	//freopen("D:\code\text\output.txt","w",stdout);
	int t;
	m[0]="zero";
	m[2]="two";
	m[4]="four";
	m[6]="six";
	m[9]="nine";
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int len=str.length();
		for(int i=0;i<len;i++)
		{
			if(str[i]>='0'&&str[i]<='9')
			{
				// if(str[i]=='0'||str[])
				if(m[(int)(str[i]-'0')].length()>0)
					cout<<str[i];
			}else
			{
				string temp=str.substr(i,3);
				
				if(temp==m[2])
				{
					cout<<2;
					i+=2;
					continue;
				}else if(temp==m[6])
				{
					cout<<6;
					i+=2;
					continue;
				}

				temp=str.substr(i,4);
				if(temp==m[0])
				{
					cout<<0;
					i+=3;
					continue;
				}else if(temp==m[4])
				{
					cout<<4;
					i+=3;
					continue;
				}else if(temp==m[9])
				{
					cout<<9;
					i+=3;
					continue;
				}
			}	
		}
		cout<<endl;
	}
	
	
	
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '
');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}


本博客为本人原创,如需转载,请必须声明博客的源地址。 本人博客地址为:www.cnblogs.com/qieqiemin/ 希望所写的文章对您有帮助。
原文地址:https://www.cnblogs.com/qieqiemin/p/11009961.html