Skip to main content
  1. Posts/

uva 401 Palindromes

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 题意:问一个字符串是不是回文串,是不是镜像串。镜像串的意思是。。从镜子里看还一样。。给定了一些存在镜像的字母和数字。。 思路:回文串的判断用c++的string要更容易一些。。直接reverse一下。。判断是否相等就行。。。然后需要注意的是。。如果某个字符补存在镜像那么一定不是镜像串

如果某个字符不存在镜像那么一定不是镜像串!

如果某个字符不存在镜像那么一定不是镜像串!

蠢哭惹好么。。。。

  1* ***********************************************
  2Author :111qqz
  3Created Time :20160120 星期三 160057
  4File Name :code/uva/401.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33string a,b;
 34char tmp[1000005];
 35map<char,char>mp;
 36void init()
 37{
 38    mp.clear();
 39    mp['A']='A';
 40
 41    mp['E']='3';
 42    mp['3']='E';
 43
 44    mp['H']='H';
 45    mp['I']='I';
 46
 47    mp['J']='L';
 48    mp['L']='J';
 49
 50    mp['M']='M';
 51    mp['O']='O';
 52    mp['0']='O';
 53
 54    mp['S']='2';
 55    mp['2']='S';
 56
 57    mp['T']='T';
 58    mp['U']='U';
 59    mp['V']='V';
 60    mp['W']='W';
 61    mp['X']='X';
 62    mp['Y']='Y';
 63
 64    mp['Z']='5';
 65    mp['5']='Z';
 66
 67    mp['1']='1';
 68    mp['8']='8';
 69}
 70
 71void solve ( bool x,bool y)
 72{
 73    if (!x&&!y) puts(" -- is not a palindrome.");
 74    if (x&&y) puts(" -- is a mirrored palindrome.");
 75    if (x&&!y) puts(" -- is a regular palindrome.");
 76    if (!x&&y) puts(" -- is a mirrored string.");
 77}
 78
 79bool pal(string x)
 80{
 81    int len = x.length();
 82    for ( int i = 0 ; i< len/2  ; i++)
 83    {
 84	if (x[i]!=x[len-1-i]) return false;
 85    }
 86    return true;
 87}
 88bool mirr(string x,string y)
 89{
 90    int len = x.length();
 91    for ( int i = 0 ; i < len/2 ;  i++)
 92    {
 93	if (x[i]!=y[len-1-i]) return false;
 94    }
 95    return true;
 96}
 97int main()
 98{
 99
100	#ifndef  ONLINE_JUDGE
101	freopen("code/in.txt","r",stdin);
102  #endif
103	init();
104	while (scanf("%s",tmp)!=EOF)
105	{
106	    a = tmp;
107	    bool ok1 = false;
108	    bool ok2 = false;
109	    b = a;
110	    reverse(b.begin(),b.end());
111	    if (a==b) ok1= true;
112	    ok1 = pal(b);
113	    int len = b.length();
114	    int cnt = 0 ;
115	    for ( int i = 0 ; i < len ; i++ )
116	    {
117		if (mp.count(b[i])==1)
118		{
119		    cnt++;
120		    b[i] = mp[b[i]];
121		}
122	    }
123	    cout<<a;
124	    if (a==b&&cnt==len) ok2=true;
125
126
127	    solve(ok1,ok2);
128
129	    cout<<endl;
130	}
131
132  #ifndef ONLINE_JUDGE
133  fclose(stdin);
134  #endif
135    return 0;
136}

Related

uva 10420 - List of Conquests

·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1361 题意:给n个带空格的字符串,第一个单词是国家,统计每个国家的字符串的个数。 思路:getline函数。。。find函数。。。substr函数。。。map…..

codeforces 612 A. The Text Splitting

http://codeforces.com/contest/612/problem/A 水题…直接枚举就好。 1/* *********************************************** 2Author :111qqz 3Created Time :2015年12月25日 星期五 22时58分26秒 4File Name :code/cf/edu4/A.cpp 5************************************************ */ 6 7#include <cstdio> 8#include <cstring> 9#include <iostream> 10#include <algorithm> 11#include <vector> 12#include <queue> 13#include <set> 14#include <map> 15#include <string> 16#include <cmath> 17#include <cstdlib> 18#include <ctime> 19#define fst first 20#define sec second 21#define lson l,m,rt<<1 22#define rson m+1,r,rt<<1|1 23#define ms(a,x) memset(a,x,sizeof(a)) 24typedef long long LL; 25#define pi pair < int ,int > 26#define MP make_pair 27 28using namespace std; 29const double eps = 1E-8; 30const int dx4[4]={1,0,0,-1}; 31const int dy4[4]={0,-1,1,0}; 32const int inf = 0x3f3f3f3f; 33const int N=105; 34int n,p,q; 35char st[N]; 36bool v[10005]; 37int main() 38{ 39 #ifndef ONLINE_JUDGE 40 freopen("code/in.txt","r",stdin); 41 #endif 42 cin>>n>>p>>q; 43 cin>>st; 44 ms(v,false); 45 int b,c; 46 for ( int i = 0 ; i*p<=105 ; i++ ) 47 { 48 for ( int j = 0 ; j*q <= 105 ; j++) 49 { 50 v[i*p+j*q] = true; 51 if (i*p+j*q==n) 52 { 53 b = i; 54 c = j; 55 } 56 } 57 } 58// cout<<"b:"<<b<<endl; 59// cout<<"c:"<<c<<endl; 60 if (!v[n]) 61 { 62 puts("-1"); 63 } 64 else 65 { 66 int cnt = 0 ; 67 printf("%d\n",b+c); 68 for ( int i = 1 ; i <= b ; i++) 69 { 70 for ( int i = 0 ; i < p ; i++) 71 printf("%c",st[cnt]),cnt++; 72 printf("\n"); 73 } 74 for ( int i =1 ; i <= c ; i++) 75 { 76 for ( int i = 0 ; i < q ; i++) 77 printf("%c",st[cnt]),cnt++; 78 printf("\n"); 79 } 80 } 81 82 83 84 #ifndef ONLINE_JUDGE 85 fclose(stdin); 86 #endif 87 return 0; 88}

codeforces #327 B Rebranding

·1 min
http://codeforces.com/contest/591/problem/B 题意:给定一个字符串。给出m组替换。对于某一组替换,给出x,y。将字符串中所有的字符x换成y,所有的字符y换成x. 字符串仅包含英文小写字母。