Kattis - yoda 【字符串】
分析
给出两个串 从末尾开始对齐 每位对齐后,每一位 遍历
如果 第一串 的那位 < 第二串 的 那么 第一串的那位 就删去
如果 等于 两位 都保留
如果 大于 那么 保留 第二串的 那位
如果 最后 删完了 那一串 就输出 YODA
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 1e9 + 5;
const int MOD = 1e9 + 7;
int main()
{
string s1, s2;
string c1 = "", c2 = "";
cin >> s1 >> s2;
int len1 = s1.size(), len2 = s2.size();
int i, j;
for (i = len1 - 1, j = len2 - 1; i >= 0 && j >= 0; i--, j--)
{
if (s1[i] < s2[j])
c2 += s2[j];
else if (s1[i] == s2[j])
{
c1 += s1[i];
c2 += s2[j];
}
else
c1 += s1[i];
}
if (i >= 0)
{
for ( ; i >= 0; i--)
c1 += s1[i];
}
if (j >= 0)
{
for ( ; j >= 0; j--)
c2 += s2[j];
}
if (c1.size())
{
for (i = c1.size() - 1; i >= 0; i--)
{
if (c1[i] != '0' || (c1[i] == '0' && i == 0))
{
cout << c1[i];
break;
}
}
for (i-- ; i >= 0; i--)
cout << c1[i];
}
else
cout << "YODA";
printf("\n");
if (c2.size())
{
for (i = c2.size() - 1; i >= 0; i--)
{
if (c2[i] != '0' || (c2[i] == '0' && i == 0))
{
cout << c2[i];
break;
}
}
for (i-- ; i >= 0; i--)
cout << c2[i];
}
else
cout << "YODA";
printf("\n");
}
Kattis - yoda 【字符串】的更多相关文章
- Kattis - whatdoesthefoxsay —— 字符串
题目: Kattis - whatdoesthefoxsay Determined to discover the ancient mystery—the sound that the fox ...
- Kattis - virus【字符串】
Kattis - virus[字符串] 题意 有一个正常的DNA序列,然后被病毒破坏.病毒可以植入一段DNA序列,这段插入DNA序列是可以删除正常DNA序列中的一个连续片段的. 简单来说就是,给你一段 ...
- Kattis - names Palindrome Names 【字符串】
题目链接 https://open.kattis.com/problems/names 题意 给出一个字符串 有两种操作 0.在字符串的最末尾加一个字符 1.更改字符串中的一个字符 求最少的操作步数使 ...
- Kattis - prva 【字符串】
题意 从上到下 或者 从左到右 组成的长度 >= 2 的字符串 如果遇到 # 就断掉 输出 字典序最小的那一个 思路 只要从上到下 和从左到右 分别遍历一遍,将 长度 >= 2 的字符串 ...
- Subsequences in Substrings Kattis - subsequencesinsubstrings (暴力)
题目链接: Subsequences in Substrings Kattis - subsequencesinsubstrings 题目大意:给你字符串s和t.然后让你在s的所有连续子串中,找出这些 ...
- Python高手之路【六】python基础之字符串格式化
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[PEP-3101] This ...
- 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率
之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...
- java中的字符串相关知识整理
字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...
- JavaScript 字符串实用常操纪要
JavaScript 字符串用于存储和处理文本.因此在编写 JS 代码之时她总如影随形,在你处理用户的输入数据的时候,在读取或设置 DOM 对象的属性时,在操作 Cookie 时,在转换各种不同 Da ...
随机推荐
- int a[3];中a+1与&a+1差别 -- C
int a[3]; a 和 &a 的地址一样的. a+1 == a + 1*sizeof(int);跳跃是一个数组元素大小 &a+1 == a + 3*sizeof(int);跳跃是整 ...
- 如果你报createSQLQuery is not valid without active transaction,请看这里
原文:https://blog.csdn.net/yinjian520/article/details/8666695 很多时候我们使用hibernate的session时,都是让session在某一 ...
- MySQL 数据库备份种类以及经常使用备份工具汇总
mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master st ...
- YUV图像合成原理
http://blog.csdn.net/zwz1984/article/details/50403150 http://zhongcong386.blog.163.com/blog/static/1 ...
- spring boot 使用拦截器 实现 用户登录拦截
登录拦截和和权限拦截实现类似 首先自定义一个[DefineAdapter]类,这个类我是用来放自定义的配置(比如 自定义请求参数,自定义拦截器等),集成WebMvcConfigurerAdapte ...
- 千万级的大表!MySQL这样优化更好
对于一个千万级的大表,现在可能更多的是亿级数据量,很多人第一反应是各种切分,可结果总是事半功倍,或许正是我们优化顺序的不正确.下面我们来谈谈怎样的优化顺序可以让效果更好. MySQL数据库一般都是按照 ...
- Redis用LPUSH和RPOP实现消息队列
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ServiceS ...
- [译]GLUT教程 - 创建和关闭子窗体
Lighthouse3d.com >> GLUT Tutorial >> Subwindows >> Creating and Destroying Subwind ...
- Linux的驱动模块管理:modprobe
由一段脚本開始: MODULE_PATH=/lib/modules/`uname -r` if [ ! -f ${MODULE_PATH}/modules.dep.bb ]; then # depmo ...
- 关于reset.css的那些事
分析过程:body: 发现在没有填写任何内容的情况下是没有margin 的 只有在加入了文字或者div中以后才有了margin(废话)那么 我想问一下 body的padding 默认的有吗??在哪里 ...