题目链接:https://vjudge.net/problem/CodeForces-1156B

题意:给定一串字符,相邻字符的ASCII码不能是相邻的数字,比如ABC,假设ASCII码为,99 100 101 ,

就是不符合题意的字符串,ACF,就可以。

思路:从相邻字符的ASCII码不能是相邻的数字,可以想到字符串之间ASCII码至少差2,然后发现

ACE...假设是奇数ASCII码,BDF是偶数ASCII码,那么我们不妨把他们分成两组,

奇数的字符,偶数的字符,那就简单了,我们可以直接先把奇数的输出,再把偶数的输出,那么字符串

之间相邻字符的ASCII码不能是相邻的数字就很好来解决了,下面字符串都转化为数字,列举一些情况

①  只有偶数

②  只有奇数

③   1 3 5 7 2

④   1 3 5 7 6

⑤    1 3 2

⑥    1 3 2 4

下面四种情况判定下就OK了,代码有呼应。


 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std; typedef long long LL;
#define inf (1LL << 25)
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--) int main(){ ios::sync_with_stdio(false);
cin.tie(); char str[];
vector<int> one;
vector<int> two; int T;
cin >> T;
while(T--){ cin >> str; one.clear(); //奇数
two.clear(); //偶数
int len = strlen(str) - ;
rep(i,,len){
int tmp = str[i] - 'a' + ;
//判奇偶
if(tmp & ) one.push_back(tmp);
else two.push_back(tmp);
} //排好序,方便比较
sort(one.begin(),one.end());
sort(two.begin(),two.end());
//只有偶数
if(one.size() == ){
rep(o,,(int)two.size() - ) cout << (char)('a' + two[o] - );
cout << endl;
}
//只有奇数
else if(two.size() == ){
rep(o,,(int)one.size() - ) cout << (char)('a' + one[o] - );
cout << endl;
}
else{
int End_b = two.size() - ;
int End_a = one.size() - ; //判断③④⑤⑥的情况
if(abs(two[] - one[End_a]) != ){
rep(o,,(int)one.size() - ) cout << (char)('a' + one[o] - );
rep(o,,(int)two.size() - ) cout << (char)('a' + two[o] - );
cout << endl;
}
else if(abs(two[End_b] - one[]) != ){
rep(o,,(int)two.size() - ) cout << (char)('a' + two[o] - );
rep(o,,(int)one.size() - ) cout << (char)('a' + one[o] - );
cout << endl;
}
else cout << "No answer" << endl; } } getchar(); getchar();
return ;
}

Ugly Pairs CodeForces - 1156B的更多相关文章

  1. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  2. Educational Codeforces Round 64 (Rated for Div. 2) A,B,C,D,E,F

    比赛链接: https://codeforces.com/contest/1156 A. Inscribed Figures 题意: 给出$n(2\leq n\leq 100)$个数,只含有1,2,3 ...

  3. Educational Codeforces Round 64(ECR64)

    Educational Codeforces Round 64 CodeForces 1156A 题意:1代表圆,2代表正三角形,3代表正方形.给一个只含1,2,3的数列a,ai+1内接在ai内,求总 ...

  4. Educational Codeforces Round 64 选做

    感觉这场比赛题目质量挺高(A 全场最佳),难度也不小.虽然 unr 后就懒得打了. A. Inscribed Figures 题意 给你若干个图形,每个图形为三角形.圆形或正方形,第 \(i\) 个图 ...

  5. Codeforces Edu Round 64 A-D

    A. Inscribed Figures 分类讨论打表即可. PS:这道题翻译有歧义. 这样稍微翻转一下,就可以是\(7\)个交点呀...(大概是我没看英文题干导致的惨案) #include < ...

  6. Educational Codeforces Round 10 C. Foe Pairs 水题

    C. Foe Pairs 题目连接: http://www.codeforces.com/contest/652/problem/C Description You are given a permu ...

  7. Codeforces Round #562 (Div. 2) B. Pairs

    链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...

  8. Codeforces 1404 D. Game of Pairs

    Codeforces 1404 D.Game of Pairs 给定\(2n\)个数\(1,2,...,2n\),A 和 B 将进行交互,规则如下: A 需要将元素分成 n 组 \(\mathbf{p ...

  9. Codeforces 159D Palindrome pairs

    http://codeforces.com/problemset/problem/159/D 题目大意: 给出一个字符串,求取这个字符串中互相不覆盖的两个回文子串的对数. 思路:num[i]代表左端点 ...

随机推荐

  1. Spring Boot 知识笔记(thymleaf模板引擎)

    一.pom.xml中引入 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...

  2. Webdriver get(url)加载时间太长

    运行Selenium脚本时,发现有时候由于网络或性能问题,加载网页时间太长,无法继续执行后续操作,但是实际上元素都已经加载出来了. 解决 # 设置页面加载超时时间 d.set_page_load_ti ...

  3. 创维(Skyworth)电视 & 小米盒子3增强版

    创维(Skyworth)电视 型号:43G7200(8H87) 品类:GLED Air TV OS:酷开64位6.20.80601-806061  兼容Android L CPU:四核 Cortex ...

  4. 重启nova-scheduler服务,报错Login was refused using authentication mechanism AMQPLAIN

    问题描述 运行 systemctl restart openstack-nova-scheduler.service 失败,查看日志报错如下: 2019-12-22 14:52:27.426 1513 ...

  5. 【Docker】涨姿势,深入了解Dockerfile 中的 COPY 与 ADD 命令

    参考资料:https://www.cnblogs.com/sparkdev/p/9573248.html Dockerfile 中提供了两个非常相似的命令 COPY 和 ADD,本文尝试解释这两个命令 ...

  6. Elasticsearch详解

    Elasticsearch详解 Chandler_珏瑜 关注  5.8 2019.05.05 17:19* 字数 10971 阅读 1147评论 5喜欢 36 5.1 Lucene简介  Lucene ...

  7. sql实现MD5加密

    select substring(sys.fn_sqlvarbasetostr(HashBytes('MD5','test')),3,32)

  8. (转)MyBatis传入多个参数的问题

    背景:记录mybaitis的使用方法,博闻强记,后面尽量记忆使用. MyBatis传入多个参数的问题 MyBatis传入多个参数的问题 详细记录mybatis在传递多个参数时候的使用方法 关于Myba ...

  9. mapreduce 变量共享

    mapreduce 全局变量共享 在编写MapReduce程序时,经常会遇到这样的问题,全局变量如何保存?如何让每个处理都能获取保存的这些全局变量?使用全局变量是不可避免的,但是 在MapRdeuce ...

  10. vim文本编辑器的使用

    1.简介 vim是vi发展过来的一款文本编辑器,功能非常强大. 2.vim的工作模式 vim有三种工作模式,分别为命令模式.编辑模式.末行模式: 1)命令模式:打开文件之后,默认进入命令模式: 2)编 ...