题目链接: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. FreeSql 访问 Oracle 解决大小写问题

    方法一 new FreeSqlBuilder() .UseSyncStructureToUpper(true) .Build() 方法二 全局转换实体属性名方法,这种只能转属性. 其实是通过Aop方法 ...

  2. 【Linux脚本学习案例】shell脚本多通道并发执行存储过程

    使用shell脚本开启多个子任务并发调用存储过程,存储过程按照通道处理数据,提高效率: 外层调用脚本: #!/bin/sh #------------------------------------- ...

  3. OpenCV使用CMake和MinGW的编译安装

    官方教程:https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows 软件环境: Qt:5.11 CMake-3.14.4 OpenCV-4.1. ...

  4. VisualStudio更改项目文件夹名称

    新建了一个空的解决方案(SolutionTest.sln),在文件夹Api中新建了一个webapi项目,物理位置为解决方案根目录下的叫Api文件夹里, 现在想把文件夹名由Api改为MyApi,需要做以 ...

  5. DRF框架和Vue框架阅读目录

    Vue框架目录 (一)Vue框架(一)——Vue导读.Vue实例(挂载点el.数据data.过滤器filters).Vue指令(文本指令v-text.事件指令v-on.属性指令v-bind.表单指令v ...

  6. C++ 结构体、模板、类、重载初使用

    目的:需要几个缓存用的数组900*750 首先定义一个模板<参数数据类型,参数1,参数2> 定义一个class类 名字自己取ap_uint0 下面是公用的数组模板[lrow][lcol] ...

  7. 爬虫基础 之 urllib

    一.urllib 1. 访问 urllib.request.urlopen() 参数: url:需要爬取的URL地址 timeout:设置等待时间,指定时间内未得到相应时抛出异常 # 导入模块 imp ...

  8. SQL Server的唯一键和唯一索引会将空值(NULL)也算作重复值

    我们先在SQL Server数据库中,建立一张Students表: CREATE TABLE [dbo].[Students]( ,) NOT NULL, ) NULL, ) NULL, [Age] ...

  9. C# 转成金额每三位逗号隔开

    long aaaa = 14200666; Console.WriteLine(aaaa.ToString("N0")); Console.WriteLine(string.For ...

  10. 用这个模型去理解CPU?