Kattis - prva 【字符串】
2024-08-27 14:09:06
题意
从上到下 或者 从左到右 组成的长度 >= 2 的字符串 如果遇到 # 就断掉
输出 字典序最小的那一个
思路
只要从上到下 和从左到右 分别遍历一遍,将 长度 >= 2 的字符串 保留下来 就可以了
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e2 + 5;
const int MOD = 1e9 + 7;
int main()
{
int n, m;
cin >> n >> m;
int i, j;
string s[25], temp;
for (i = 0; i < n; i++)
cin >> s[i];
vector <string> v;
v.clear();
for (i = 0; i < n; i++)
{
temp.clear();
for (j = 0; j < m; j++)
{
if (s[i][j] == '#')
{
if (temp.size() >= 2)
v.push_back(temp);
temp.clear();
}
else
temp += s[i][j];
}
if (temp.size() >= 2)
v.push_back(temp);
}
for (j = 0; j < m; j++)
{
temp.clear();
for (i = 0; i < n; i++)
{
if (s[i][j] == '#')
{
if (temp.size() >= 2)
v.push_back(temp);
temp.clear();
}
else
temp += s[i][j];
}
if (temp.size() >= 2)
v.push_back(temp);
}
sort(v.begin(), v.end());
cout << v[0] << endl;
}
最新文章
- 简历生成平台项目开发-STEP2问卷调查结果统计分析
- [Tip]重写PanGestureRecognizer
- ASP.NET MVC增删改查
- $(document).ready()方法的使用
- xcodebuild和xcrun实现自动打包iOS应用程序
- RejexLib
- Android TextView drawableLeft 在代码中实现
- 第三课3、ROS的launch文件
- log4xx/log4j异步日志配置示例
- [C++]Linux之虚拟文件系统[/proc]中关于CPU/内存/网络/内核等的一些概要性说明
- git clean(转载)
- JVM(二)之GC(转)
- OneZero第三周第四次站立会议(2016.4.7)
- Rabbit MQ 入门指南
- 最好的PHP博客系统
- Hibernate学习笔记四
- Javascript中判断变量是数组还是对象(array还是object)
- 厄拉多塞筛法和普通方法求素数表(python实现)
- ios常用的字符串NSString自动释放理解
- Selenium(Python)等待元素出现