//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的更多相关文章

  1. lrj计算几何模板

    整理了一下大白书上的计算几何模板. #include <cstdio> #include <algorithm> #include <cmath> #include ...

  2. 倒水问题(Fill,UVA 10603) lrj白书 p202

    看着lrj的代码自己敲了一遍,还没调试成功.... 有时间再进行完善 /* 状态start到各个状态u1,u2,u3..... 的倒水量分别为u1.dist,u2.dist,u3.dist.... * ...

  3. LRJ入门经典-0907万圣节的小L306

    原题 LRJ入门经典-0907万圣节的小L306 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 今天是万圣节,小L同学开始了 ...

  4. LRJ入门经典-0906最短公共父串305

    原题 LRJ入门经典-0906最短公共父串305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 给定字符串A和字符串B,要求 ...

  5. LRJ入门经典-0905邮票和信封305

    原题 LRJ入门经典-0905邮票和信封305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 假定一张信封最多贴5张邮票,如 ...

  6. LRJ入门经典-0903切蛋糕305

    原题 LRJ入门经典-0903切蛋糕305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 如图所示有一个矩形蛋糕,上面划分成 ...

  7. // 62.是否有利润奖--lrj private boolean isProfitsAward; // 63.利润奖--lrj_price private String profitsAward;

    // 62.是否有利润奖--lrj private boolean isProfitsAward; // 63.利润奖--lrj_price private String profitsAward; ...

  8. 第五章第二例题关于Vector(LRJ)

    vector(动态数组)(粘) 一.概述 vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector是一个容器,它能够存放各种类型的对象,简 ...

  9. 第四章第四个例题(LRJ)

    半年了,最起码的编程能力也谈不上啊,思维神马就更不不敢说了. 互联网时代讲求效率,走得慢和不走没有区别了. The war is on. (buhuidetiduokanduodajibianyehu ...

  10. 强连通分量(LRJ训练指南)

    #include <iostream> #include <queue> #include <string> #include <cstdio> #in ...

随机推荐

  1. web前端学习(三)css学习笔记部分(6)-- 选择器详解

    9.选择器详解 9.1  属性选择器 CSS3 属性选择器,在 CSS3 中,追加了三个属性选择器分别为:[att*=val].[att^=val]和[att$=val],使得属性选择器有了通配符的概 ...

  2. xml-apis.jar getTextContent() jar包冲突解决(getTextContent()方法无法找到)

    1.引用包: import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList; 2.方法中应用: ...

  3. Serializable 可串行化接口

    Serializable 可串行化接口 定义一个User类,实现Serializable接口: package com.monkey1025; import java.io.Serializable; ...

  4. DirectX11笔记(十)--Direct3D渲染6--PIXEL SHADER

    原文:DirectX11笔记(十)--Direct3D渲染6--PIXEL SHADER 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u01033 ...

  5. python Match函数

  6. vscode中编译输出c++是乱码

    vscode中编译输出c++是乱码的解决 环境说明:windows下面运行vscode win + R 右键属性 查看当前编码状态 知道当前环境的编码格式后,可以改变vscode上c++的格式 点击v ...

  7. day39-Spring 06-Spring的AOP:带有切点的切面

    环绕增强功能是最强的,它相当于前置增强和后置增强. 这就是带有切点的切面 package cn.itcast.spring3.demo4; import org.aopalliance.interce ...

  8. jq方法的注意点

    当jq方法里面引用的ajax方法和其它方法时,就需要把ajax改为同步,通过ajax方法返回值来判断下一步执行那个方法,你不做判断,浏览器编译执行的时候不会不会按你想的从上之下执行下来. 当安卓手机跟 ...

  9. hdu4310 贪心

    考虑每次血口的要少 就按照一滴血多少伤害来计算.由于直接相除有小数.考虑x/y > a/b  =>  x*b >y*a; #include<stdio.h> #inclu ...

  10. Mysterious Antiques in Sackler Museum(判断长方形)

    题目链接 参考博客Ritchie丶的博客 - UVALive 7267 Mysterious Antiques in Sackler Museum (判断长方形) 题意:大概意思就是判断四个矩形能不能 ...