Codeforces Round #234A
Inna and choose option
一个由12个字符('O'或'X')组成的字符串,这12个字符可以排列成a*b(a*b=12)的矩阵,要求矩阵某一列都是'X'。用户输入t个字符串,都是由12个'O'或'X组成,设计函数可求解符合要求矩阵的个数,并且将符合要求的矩阵大小输出。
Input:
第一行输入一个整数t(Range:1-100),t表示要输入的测试数据的个数,下面每一行输入都是一组数据被录入。
Output:
将每组数据的结果放在一行输出,format:n axb axb axb ….
n表示满足要求的矩阵个数,后面是具体的矩阵大小。
例如:
解题思路:
可以看出矩阵个数最大为6,分别是(1,12)(2,6)(3,4)(4,3)(6,2)(12,1),将这些情况枚举出来,然后for循环判断矩阵的每一列,若有一列满足条件(全为'X'),那么将这个矩阵行数列数分别保存到一个6行2列的数组的第一行,k来计数,最后k中存的就是满足条件的矩阵个数,数组里面前k行存的就是具体大小。
代码:
#include <iostream>
using namespace std;
#include <string>
#define MAX 100 int main(void)
{
string s[MAX];
int t;
void inna(string card);
cin >> t;
for(int i=;i<t;i++)
{
cin >> s[i];
} for(int i=;i<t;i++)
{
inna(s[i]);
}
return ;
} void inna(string card)
{
int i,j,k=,m;
bool flag = true;
int a[] = {,,,,,}; // 行数有六中情况
int b[] = {,,,,,}; // 列数
int n[][]; if(card == "OOOOOOOOOOOO") // 12张卡片全为o
{
cout << k << endl;
return; // 结束函数体
} for(i=;i<;i++) // i表示行数
{
for(j=;j<b[i];j++)
{
flag = true;
for(m=;m<a[i];m++)
{
if(card[j+m*b[i]]!='X')
{
flag = false;
break;
}
} if(flag)
{
n[k][] = a[i];
n[k][] = b[i];
k++;
break;
}
}
} cout << k << ' ';
for(i=;i<k;i++)
{
cout << n[i][] << 'x' << n[i][] << ' ';
}
cout << endl;
}
C++ Code
测试结果:
Codeforces Round #234A的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- [nRF51822] 8、基础实验代码解析大全 · 实验11 - PPI
前一篇分析了前十个基础实验的代码,从这里开始分析后十个~ 一.PPI原理: PPI(Programmable Peripheral Interconnect),中文翻译为可编程外设互连. 在nRF51 ...
- Android开发学习之路-该怎么学Android(Service和Activity通信为例)
在大部分地方,比如书本或者学校和培训机构,教学Android的方式都基本类似,就是告诉先上原理方法,然后对着代码讲一下. 但是,这往往不是一个很好的方法,为什么? ① 学生要掌握这个方法的用途,只能通 ...
- Atitit常见的标准化组织与规范数量jcp ecma iso
Atitit常见的标准化组织与规范数量jcp ecma iso 1. 常见的标准化组织1 1.1. 重要的基金会apache1 1.2. 美国国家标准学会(American NationalStand ...
- Leetcode-190 Reverse Bits
#190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...
- Sql Server系列:索引基础
1 索引概念 索引用于快速查找在某个列中某个特定值的行,不使用索引,数据库必须从第1条记录开始读完整个表,知道找出需要的行.表越大,查询数据所花费的时间越多.如果表中查询的列有索引,数据库能快速到达一 ...
- Newtonsoft.json中 linq to json 和序列化哪个快?
Newtonsoft.json是最常用的json序列化组件,当然他不是最快的,但是是功能最全的.. using System; using System.Collections.Generic; us ...
- Android入门(二十二)解析JSON
原文链接:http://www.orlion.ga/687/ 解析JSON的方式有很多,主要有官方提供的 JSONObject,谷歌的开源库 GSON.另外,一些第三方的开源库如 Jackson.Fa ...
- JavaScript 中的类方法,对象方法,Prototype方法
<script type="text/javascript"> function baseClass() { this.showMsg = function() { a ...
- 了解screen对象的常用视图属性
前面的话 screen对象基本上只用来表明客户端的能力,其中包括浏览器窗口外部的显示器的信息,如像素高度和宽度等.每个浏览器中的screen对象都包含着各不相同的属性.本文将详细介绍screen对象的 ...
- 【原创】开源.NET排列组合组件KwCombinatorics使用(三)——笛卡尔积组合
本博客所有文章分类的总目录:本博客博文总目录-实时更新 本博客其他.NET开源项目文章目录:[目录]本博客其他.NET开源项目文章目录 KwCombinatorics组件文章目录: 1. ...