P1603 斯诺登的密码-字符串加法的妙用
2024-10-06 11:29:58
传送门:https://www.luogu.org/problemnew/show/P1603
题意:
首先在给定的字符串中,找出特定的单词,把它转化成特定的数字,
然后在这些数字中,找出排列结果最小的一种排列;
思路:
第一步就是打表就ok,第二步,可以用字符串加法结果的大小进行排序;
遇到“找出所有排列方法中最小的一个数”,可能就要怎么做;
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#define pb push_back
using namespace std;
typedef long long ll; vector<string>q;
bool cmp (string a,string b)
{
return a+b < b+a;
}
int main(){
string s;
while(cin>>s)
{
if(s=="one"||s=="a"||s=="another"||s=="first")q.pb("");
if(s=="two"||s=="both"||s=="second")q.pb("");
if(s=="three"||s=="third")q.pb("");
if(s=="four")q.pb("");
if(s=="five")q.pb("");
if(s=="six")q.pb("");
if(s=="seven")q.pb("");
if(s=="eight")q.pb("");
if(s=="nine")q.pb("");
if(s=="ten")q.pb("");
if(s=="eleven")q.pb("");
if(s=="twelve")q.pb("");
if(s=="thirteen")q.pb("");
if(s=="fourteen")q.pb("");
if(s=="fifteen")q.pb("");
if(s=="sixteen")q.pb("");
if(s=="seventeen")q.pb("");
if(s=="eighteen")q.pb("");
if(s=="nineteen")q.pb("");
if(s=="twenty")q.pb("");
//break;
if(s[s.length()-]=='.')break; }
sort(q.begin(),q.end(),cmp);
bool isout=false;
bool canout=false;
string a="";
for(int i=;i<q.size();i++)
a+=q[i];
for(int i=;i<a.length();i++)
{
if(a[i]!='') canout=true;
if(a[i]==''&&!canout)continue;
cout<<a[i];
isout=true;
}
if(!isout)cout<<"";
cout<<endl;
return ;
}
最新文章
- webpack+vue-cli项目打包技巧
- 【requireJS路径加载】与程序员小卡的交流
- sync_with_stdio
- jQuery.ajax()的相关参数及使用
- http://runjs.cn/
- Ta-lib 函数一览
- Hark的数据结构与算法练习之多路归并排序
- Maven Project configuration is not up-to-date with pom.xml错误解决方法
- DIV+CSS外部字体引用
- 优化viewHolder
- 使用element ui 日期选择器获取值后的格式问题
- ROS_Kinetic_12 ROS程序基础Eclipse_C++(三)usb camera
- Eclipse两种部署web项目方法
- Docker JDK镜像
- JavaScript 基础(一) - JavaScript的引入方式,JavaScript 变量命名规则,JS 的五种基本数据类型,ECMAScript 算数运算符,逻辑运算符
- Python在线聊天软件(Tkinter)
- 公用表表达式(CTE)
- 词云绘制wordcloud
- vs 15 key
- MongoDB学习笔记(11) --- 聚合
热门文章
- 理解SVG中的 viewport,viewBox, preserveAspectRatio
- 【Intellij】Hot Swap Failed &; class reloaded
- Mybatis整合Spring 使用
- Java集合系列(四):HashMap、Hashtable、LinkedHashMap、TreeMap的使用方法及区别
- Python - 自学django,上线一套资产管理系统
- React-Native之打包发布(Android)
- mybatis学习笔记(一)
- ASP.NET CORE系列【七】分析NetCore启动原理
- Go中的函数和闭包
- 为什么我们不用JIRA