LRJ
//3-1
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> int main()
{
int T;
char score[];
scanf("%d", &T);
while (T-- > ) {
scanf("%s", score);
int sum = ;
int num = ;
char prev = 'X';
for (int i = ; score[i] != '\0'; i++) {
if (score[i] == 'O'){
if (prev == 'O'){
num++;
}
else {
num = ;
}
sum += num;
prev = 'O';
}
else {
prev = 'X';
}
}
printf("%d\n", sum);
} return ;
}
3-2
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
bool isNum(char c){
return c >= '' && c <= '';
}
double mass(char m){
switch (m){
case 'C': return 12.01;
case 'H': return 1.008;
case 'O': return 16.00;
case 'N': return 14.01;
default: return 0.0;
}
}
int charToInt(char c) {
if (c >= '' && c <= '')
return c - '';
else
return ;
}
int main()
{
int T;
char molar[];
scanf("%d", &T);
while (T-- > ) {
scanf("%s", molar);
double sum = ;
bool prevIsNum = false;
char m = 'X'; // m is the previous molecular (C, H, O, N), 'X' is the previous for the first molecular, mass('X') == 0
for (int i = ; molar[i] != '\0'; i++) {
if (isNum(molar[i])){
if (prevIsNum){
char hiDigit = molar[i - ];
char loDigit = molar[i];
sum += mass(m) * (charToInt(hiDigit) * + charToInt(loDigit));
}
else {
}
prevIsNum = true;
}
else { // C, H, O, N
if (prevIsNum){
// if previous two letters are numbers, the mass is caculated elsewhere
if (!isNum(molar[i - ])){
char loDigit = molar[i - ];
sum += mass(m) * charToInt(loDigit);
}
}
else{
// add previous m
sum += mass(m);
}
m = molar[i];
prevIsNum = false;
}
}
// last letter is C/H/O/N
if (!prevIsNum)
sum += mass(m);
printf("%.3f\n", sum);
}
return ;
}
3-3
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> int main()
{
int T;
int n;
scanf("%d", &T);
while (T-- > ) {
scanf("%d", &n);
int counts[] = { };
for (int i = ; i <= n; i++){
int j = i;
while (j > ) {
counts[j % ]++;
j /= ;
}
} for (int i = ; i < ; i++){
printf("%d", counts[i]);
if (i == )
printf("\n");
else
printf(" ");
}
} return ;
}
3-4
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> bool sameStr(char *s1, char *s2, int len)
{
for (int i = ; i < len; i++)
if (s1[i] != s2[i])
return false; return true;
} int main()
{
int T;
char s[];
scanf("%d", &T);
while (T-- > ) {
scanf("%s", s); if (s[] != '\0'){
char first = s[]; // find a equal char
int start = ; // start point for searching
while (true) {
int idx = start;
for (; s[idx] != '\0'; idx++){
if (first == s[idx])
break;
} if (s[idx] != '\0'){
// compare s[0..idx-1] with s[idx..] of same length = idx
if (sameStr(s, s + idx, idx)){
printf("%d\n\n", idx);
break;
} start = idx + ;
}
else{ // not found
break;
}
}
}
else { // empty string } } return ;
}
3-5
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> int main()
{
int T = ;
char puzzle[][];
char newline;
int empty_row, empty_col; while (true) { for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
scanf("%c", &puzzle[i][j]);
if (i == && j == && puzzle[][] == 'Z'){
// end of test cases
return ;
}
if (puzzle[i][j] == ' '){
empty_row = i;
empty_col = j;
} }
scanf("%c", &newline); // swallow the new line
} // process moves
char m;
bool error = false;
while (true){
scanf("%c", &m);
if (m == '') break;
switch (m){
case 'A':
if (empty_row == ){
error = true;
break;
}
// swap with above
puzzle[empty_row][empty_col] = puzzle[empty_row - ][empty_col];
puzzle[empty_row - ][empty_col] = ' ';
empty_row--;
break;
case 'B':
if (empty_row == ){
error = true;
break;
}
// swap with bottom
puzzle[empty_row][empty_col] = puzzle[empty_row + ][empty_col];
puzzle[empty_row + ][empty_col] = ' ';
empty_row++;
break;
case 'L':
if (empty_col == ){
error = true;
break;
}
// swap with left
puzzle[empty_row][empty_col] = puzzle[empty_row][empty_col - ];
puzzle[empty_row][empty_col - ] = ' ';
empty_col--;
break;
case 'R':
if (empty_col == ){
error = true;
break;
}
// swap with above
puzzle[empty_row][empty_col] = puzzle[empty_row][empty_col + ];
puzzle[empty_row][empty_col + ] = ' ';
empty_col++;
break;
}
}
scanf("%c", &newline); // swallow the new line printf("Puzzle #%d:\n", T++);
if (error){
printf("This puzzle has no final configuration.\n");
}
else {
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
printf("%c", puzzle[i][j]);
if (j != ) printf(" ");
}
printf("\n");
}
}
printf("\n");
} }
3-6
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
struct grid{
char c;
int n;
};
struct grid puzzle[][];
int main()
{
int r, c;
char newline;
int T = ;
while (true) {
scanf("%d", &r); if (r == ) break;
scanf("%d", &c);
scanf("%c", &newline); // swallow the new line
int num = ;
for (int row = ; row < r; row++){
for (int col = ; col < c; col++) {
scanf("%c", &puzzle[row][col].c);
if ((puzzle[row][col].c != '*') && // white
(row == || col == || puzzle[row - ][col].c == '*' || puzzle[row][col - ].c == '*')){ // eligible
puzzle[row][col].n = num++;
}
else if (puzzle[row][col].c == '*') { // black
puzzle[row][col].n = -;
}
else { // illegible white
puzzle[row][col].n = ;
}
}
scanf("%c", &newline); // swallow the new line
}
printf("puzzle #%d:\n", T++);
// Across words
printf("Across\n");
for (int row = ; row < r; row++){
int col = ;
while (col < c) {
while (col < c && puzzle[row][col].n < ) { // skip black
col++;
}
if (col < c) {
printf("%d.", puzzle[row][col].n);
}
while (col < c && puzzle[row][col].n >= ) { // eligible and illegible white
printf("%c", puzzle[row][col].c);
col++;
}
printf("\n");
while (col < c && puzzle[row][col].n < ) { // skip black
col++;
}
}
}
// Down words
printf("Down\n");
for (int row = ; row < r; row++){
for (int col = ; col < c; col++) {
if ((puzzle[row][col].c != '*') &&
(row == || puzzle[row - ][col].c == '*')) {
printf("%d.", puzzle[row][col].n);
for (int dr = row; dr < r && puzzle[dr][col].c != '*'; dr++){
printf("%c", puzzle[dr][col].c);
}
printf("\n");
}
}
}
printf("\n"); // Separate output for successive input puzzles by a blank line.
/*
for (int row = 0; row < r; row++) {
for (int col = 0; col < c; col++) {
printf("%c ", puzzle[row][col].c);
}
printf("\n");
}
for (int row = 0; row < r; row++) {
for (int col = 0; col < c; col++) {
printf("%d ", puzzle[row][col].n);
}
printf("\n");
}
*/
}
return ;
}
LRJ的更多相关文章
- lrj计算几何模板
整理了一下大白书上的计算几何模板. #include <cstdio> #include <algorithm> #include <cmath> #include ...
- 倒水问题(Fill,UVA 10603) lrj白书 p202
看着lrj的代码自己敲了一遍,还没调试成功.... 有时间再进行完善 /* 状态start到各个状态u1,u2,u3..... 的倒水量分别为u1.dist,u2.dist,u3.dist.... * ...
- LRJ入门经典-0907万圣节的小L306
原题 LRJ入门经典-0907万圣节的小L306 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 今天是万圣节,小L同学开始了 ...
- LRJ入门经典-0906最短公共父串305
原题 LRJ入门经典-0906最短公共父串305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 给定字符串A和字符串B,要求 ...
- LRJ入门经典-0905邮票和信封305
原题 LRJ入门经典-0905邮票和信封305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 假定一张信封最多贴5张邮票,如 ...
- LRJ入门经典-0903切蛋糕305
原题 LRJ入门经典-0903切蛋糕305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 如图所示有一个矩形蛋糕,上面划分成 ...
- // 62.是否有利润奖--lrj private boolean isProfitsAward; // 63.利润奖--lrj_price private String profitsAward;
// 62.是否有利润奖--lrj private boolean isProfitsAward; // 63.利润奖--lrj_price private String profitsAward; ...
- 第五章第二例题关于Vector(LRJ)
vector(动态数组)(粘) 一.概述 vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector是一个容器,它能够存放各种类型的对象,简 ...
- 第四章第四个例题(LRJ)
半年了,最起码的编程能力也谈不上啊,思维神马就更不不敢说了. 互联网时代讲求效率,走得慢和不走没有区别了. The war is on. (buhuidetiduokanduodajibianyehu ...
- 强连通分量(LRJ训练指南)
#include <iostream> #include <queue> #include <string> #include <cstdio> #in ...
随机推荐
- Spring 社区的首个国产开源项目顺利毕业
相信大家对上周的 <来自 Spring Cloud 官方的消息,Spring Cloud Alibaba 即将毕业>文章记忆犹新.本周,Spring Cloud Alibaba 正式毕业, ...
- 基于 DataLakeAnalytics 的数据湖实践
随着软硬件各方面条件的成熟,数据湖(Data Lake)已经越来越受到各大企业的青睐, 与传统的数仓实践不一样的是,数据湖不需要专门的“入仓”的过程,数据在哪里,我们就从哪里读取数据进行分析.这样的好 ...
- ASP.NET 自定义服务器控件
文章内容 本文通过创建一个最简单的服务器控件,演示开发服务器端控件的流程. 文章内容整理自MSDN的编程指南,原文地址在文章末尾的资源中. 本文创建一个简单的服务器控件,名为 RedLabel. ...
- Python中 sys.argv的用法简明解释
Python中 sys.argv[]的用法简明解释 sys.argv[]说白了就是一个从程序外部获取参数的桥梁,这个“外部”很关键,所以那些试图从代码来说明它作用的解释一直没看明白.因为我们从外部取得 ...
- 从零开始写一个npm包,一键生成react组件(偷懒==提高效率)
前言 最近写项目开发新模块的时候,每次写新模块的时候需要创建一个组件的时候(包含组件css,index.js,组件js),就只能会拷贝其他组件修改名称 ,但是写了1-2个后发现效率太低了,而且极容易出 ...
- spring中 使用说明
在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类 ...
- JavaScript--封装好的运动函数+旋转木马例子
封装好的运动函数: 1.能控制目标元素的多种属性 2.能自动获取元素的样式表: 3.获取样式函数兼容 4.能对于元素的多属性进行动画(缓动动画)修改 5.能区分透明度等没单位的属性和px属性的变化 a ...
- 数据库lib7第4题创建存储过程
1. 传入2个字符串变量,其中,每个字符串是用分号(:)分隔的字串形式, 比如str1=’ab12;ab;cccc;tty’, str2=’1;6sf;8fffff;dd’, 注意,字符串是用户输入的 ...
- ubuntu下C操作Mysql数据库第一步
学习于: http://armsword.com/2013/06/20/ubuntu-c-mysql.html
- Spring → 04:Bean(1)
一.Bean概念 Spring Bean是被实例的,组装的及被Spring 容器管理的Java对象. Spring 容器会自动完成@bean对象的实例化. 创建应用对象之间的协作关系的行为称为:装配( ...