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 ...
随机推荐
- vs2012_error C2061: 语法错误: 标识符“uint64_t”
加入头文件#include <stdint.h>
- JavaScript Array pop(),shift()函数
pop() 删除数组的最后一个元素并返回删除的元素 shift() 删除并返回数组的第一个元素
- Android蓝牙
代码地址如下:http://www.demodashi.com/demo/12772.html 前言:最近,新换了一家公司,公司的软件需要通过蓝牙与硬件进行通讯,于是趁此机会将Android蓝牙详细的 ...
- 自上而下渐显图片的CSS3实现
代码地址如下:http://www.demodashi.com/demo/12160.html 目录 一.实现思路 二.所用特性 三.示例代码 四.实例效果 五.组件化(Vue) 一.实现思路 从效果 ...
- Linux的IO栈
- jar包解压与打包
首先感谢大神的指导:https://blog.csdn.net/mr_pang/article/details/47028921 1.首先准备一个能运行的jar文件,我们使用第三方解压工具进行解压wi ...
- lua string库
--lua中字符串索引从前往后是1,2,……,从后往前是-1,-2……. --string库中所有的function都不会直接操作字符串,只返回一个结果. -------------------- ...
- [译]GLUT教程 - 鼠标
Lighthouse3d.com >> GLUT Tutorial >> Input >> The Mouse 上一节我们讨论了怎么用GLUT的键盘函数跟OpenG ...
- Ubuntu配置apache2.4配置虚拟主机遇到的问题
update: 偶然看到了 apache的更新说明,直接贴个地址过来吧. http://httpd.apache.org/docs/2.4/upgrading.html 最近想把web开发目录从/va ...
- android 软键盘监听显示和隐藏
githup中找到:https://github.com/yescpu/KeyboardChangeListener import android.app.Activity; import andro ...