当前位置: 代码迷 >> 综合 >> hihocoder - 1082,1094
  详细解决方案

hihocoder - 1082,1094

热度:94   发布时间:2024-01-12 15:27:33.0


时间限制: 1000ms
单点时限: 1000ms
内存限制: 256MB

描述


fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。为了使句子不缺少成分,统一换成 “fjxmlhx” 。

输入

输入包括多行。

每行是一个字符串,长度不超过200。

一行的末尾与下一行的开头没有关系。

输出

输出包含多行,为输入按照描述中变换的结果。

样例输入
The Marshtomp has seen it all before.
marshTomp is beaten by fjxmlhx!
AmarshtompB
样例输出
The fjxmlhx has seen it all before.
fjxmlhx is beaten by fjxmlhx!
AfjxmlhxB

枚举处理字符串就好

代码:

#include <bits/stdc++.h>
using namespace std;
#define M 205
char str[M];
bool vis[M]; //记录每个字母是不是在单词marshtomp中
int main()
{int i,j,len;while(gets(str)){len=strlen(str);string ans="";bool f=false; //当前是不是在处理单词marshtompint t=0;      //当前连续出现了单词里的几个字母memset(vis,false,sizeof(vis));if(str[0]=='m'||str[0]=='M'){f=true; t=1;}for(i=1;i<len;i++){switch(str[i]){case 'm':case 'M':if(!(str[i-1]=='o'||str[i-1]=='O')){f=true;t=1;}else{if(f)t++;elset=1;}break;case 'a':case 'A':if(!(str[i-1]=='m'||str[i-1]=='M')){f=false;t=0;}else{if(f)t++;elset=0;}break;case 'r':case 'R':if(!(str[i-1]=='a'||str[i-1]=='A')){f=false; t=0;}else{if(f)t++;elset=0;}break;case 's':case 'S':if(!(str[i-1]=='r'||str[i-1]=='R')){f=false;t=0;}else{if(f)t++;elset=0;}break;case 'h':case 'H':if(!(str[i-1]=='s'||str[i-1]=='S')){f=false; t=0;}else{if(f)t++;elset=0;}break;case 't':case 'T':if(!(str[i-1]=='h'||str[i-1]=='H')){f=false; t=0;}else{if(f)t++;elset=0;}break;case 'o':case 'O':if(!(str[i-1]=='t'||str[i-1]=='T')){f=false; t=0;}else{if(f)t++;elset=0;}break;case 'p':case 'P':if((str[i-1]=='m'||str[i-1]=='M')){if(f&&t==8){for(j=i-8;j<=i;j++)vis[j]=true;}else{f=false; t=0;}}else{f=false; t=0;}break;}}for(i=0;i<len;i++)  //生成答案{if(vis[i]){if((str[i]=='m'||str[i]=='M')&&(str[i+1]=='a'||str[i+1]=='A'))ans+="fjxmlhx";}else{ans+=str[i];}}cout<<ans<<endl;}return 0;
}

时间限制: 10000ms
单点时限: 1000ms
内存限制: 256MB

描述

Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.

Fortunately, Little Hi has a map of the city. The map can be considered as a grid of N*M blocks. Each block is numbered by a pair of integers. The block at the north-west corner is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a character, describing the construction on that block: '.' for empty area, 'P' for parks, 'H' for houses, 'S' for streets, 'M' for malls, 'G' for government buildings, 'T' for trees and etc.

Given the blocks of 3*3 area that surrounding Little Hi(Little Hi is at the middle block of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented, the upper side of the surrounding area may be actually north side, south side, east side or west side.

输入

Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+1: each line contains M characters, describing the city's map. The characters can only be 'A'-'Z' or '.'.
Line N+2~N+4: each line 3 characters, describing the area surrounding Little Hi.

输出

Line 1~K: each line contains 2 integers X and Y, indicating that block (X, Y) may be Little Hi's position. If there are multiple possible blocks, output them from north to south, west to east.

样例输入
8 8
...HSH..
...HSM..
...HST..
...HSPP.
PPGHSPPT
PPSSSSSS
..MMSHHH
..MMSH..
SSS
SHG
SH.
样例输出
5 4

题意:给出一张城市地图(不同字母代表不同建筑)此地图是按上北下南左西右东的,给出3*3的小地图,但小地图的上下左右的方向是未知的,让求小地图中心在大地图中的位置。有多个答案则按从北到南,从西到东输出。

我们可以枚举小地图的方向,然后带入大地图中

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 205
int n,m;
bool vis[M][M];  //去掉重复答案用
char mp[M][M],t[10][10];
char sur[10][10],tmp[10][10];
struct node{    //存答案int x,y;bool operator < (const node & obj)const{return x<obj.x||((x==obj.x)&&(y<obj.y));}
}ans[M*M];
bool judge(int x,int y) //判断小地图是否与大地图相符
{if((mp[x][y]==sur[0][0]&&mp[x][y+1]==sur[0][1]&&mp[x][y+2]==sur[0][2])&&(mp[x+1][y]==sur[1][0]&&mp[x+1][y+1]==sur[1][1]&&mp[x+1][y+2]==sur[1][2])&&(mp[x+2][y]==sur[2][0]&&mp[x+2][y+1]==sur[2][1]&&mp[x+2][y+2]==sur[2][2])) return true;return false;
}
int main()
{int i,j;scanf("%d%d",&n,&m);for(i=0;i<n;i++)scanf("%s",mp[i]);for(i=0;i<3;i++){scanf("%s",sur[i]);for(j=0;j<3;j++)t[i][j]=sur[i][j];}int num=0;for(i=0;i<n-2;i++){for(j=0;j<m-2;j++){if(judge(i,j)&&!vis[i+2][j+2]){vis[i+2][j+2]=true;ans[num].x=i+1+1;ans[num].y=j+1+1;num++;}}}tmp[0][0]=t[0][2]; tmp[0][1]=t[1][2]; tmp[0][2]=t[2][2];tmp[1][0]=t[0][1]; tmp[1][1]=t[1][1]; tmp[1][2]=t[2][1];tmp[2][0]=t[0][0]; tmp[2][1]=t[1][0]; tmp[2][2]=t[2][0];for(i=0;i<3;i++)for(j=0;j<3;j++)sur[i][j]=tmp[i][j];/*for(i=0;i<3;i++){for(j=0;j<3;j++)cout<<sur[i][j]<<" ";cout<<endl;}*/for(i=0;i<n-2;i++){for(j=0;j<m-2;j++){if(judge(i,j)&&!vis[i+2][j+2]){vis[i+2][j+2]=true;ans[num].x=i+1+1;ans[num].y=j+1+1;num++;}}}tmp[0][0]=t[2][2]; tmp[0][1]=t[2][1]; tmp[0][2]=t[2][0];tmp[1][0]=t[1][2]; tmp[1][1]=t[1][1]; tmp[1][2]=t[1][0];tmp[2][0]=t[0][2]; tmp[2][1]=t[0][1]; tmp[2][2]=t[0][0];for(i=0;i<3;i++)for(j=0;j<3;j++)sur[i][j]=tmp[i][j];/*for(i=0;i<3;i++){for(j=0;j<3;j++)cout<<sur[i][j]<<" ";cout<<endl;}*/for(i=0;i<n-2;i++){for(j=0;j<m-2;j++){if(judge(i,j)&&!vis[i+2][j+2]){vis[i+2][j+2]=true;ans[num].x=i+1+1;ans[num].y=j+1+1;num++;}}}tmp[0][0]=t[2][0]; tmp[0][1]=t[1][0]; tmp[0][2]=t[0][0];tmp[1][0]=t[2][1]; tmp[1][1]=t[1][1]; tmp[1][2]=t[0][1];tmp[2][0]=t[2][2]; tmp[2][1]=t[1][2]; tmp[2][2]=t[0][2];for(i=0;i<3;i++)for(j=0;j<3;j++)sur[i][j]=tmp[i][j];/*for(i=0;i<3;i++){for(j=0;j<3;j++)cout<<sur[i][j]<<" ";cout<<endl;}*/for(i=0;i<n-2;i++){for(j=0;j<m-2;j++){if(judge(i,j)&&!vis[i+2][j+2]){vis[i+2][j+2]=true;ans[num].x=i+1+1;ans[num].y=j+1+1;num++;}}}sort(ans,ans+num);/*int tot=1;for(i=1;i<num;i++){if(ans[i].x==ans[i-1].x&&ans[i].y==ans[i-1].y) continue;else{ans[tot].x=ans[i].x;ans[tot].y=ans[i].y;tot++;}}*/for(i=0;i<num;i++)printf("%d %d\n",ans[i].x,ans[i].y);return 0;
}


  相关解决方案