//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. JavaScript文件与HTML文件本地连接

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 第十章—DOM(0)—NODE类型

    DOM1定义了一个node接口,该接口由DOM的所有节点类型实现. 所有的节点都存在这样或那样的关系.在HTML中,head,body可以看出是html的子元素,html是head,body的父元素, ...

  3. 导入pymysql模块出错:No module named 'pymysql'

    前提: 使用的版本为:Python 3.6.4 pymysql已经被成功安装了,并通过命令行的方式验证已成功安装. 但在pycharm中运行工程时候时候报错:No module named 'pymy ...

  4. ES6 中变量的解构赋值

    1. 数组的解构赋值 解构: ES6 中允许按照一定的模式从数组和对象中提取值,然后对变量进行赋值,这被称为解构(Destructuring). 1. 基本用法 本质上,这种写法属于"模式匹 ...

  5. R语言分类算法之随机森林

    R语言分类算法之随机森林 1.原理分析: 随机森林是通过自助法(boot-strap)重采样技术,从原始训练样本集N中有放回地重复随机抽取k个样本生成新的训练集样本集合,然后根据自助样本集生成k个决策 ...

  6. 【51nod1563】坐标轴上的最大团 贪心

    题面 坐标轴上有n个点,每个点有一个权值.第i个点的坐标是 xi ,权值是 wi .现在对这些点建图.对于点对 (i,j) ,如果 \(|xi−xj|≥wi+wj\) ,那么就给第i个点和第j个点之间 ...

  7. Leetcode4.Median of Two Sorted Arrays两个排序数组的中位数

    给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 你可以假设 nums1 和 nums2 不同 ...

  8. GNN 相关资料记录;GCN 与 graph embedding 相关调研;社区发现算法相关;异构信息网络相关;

    最近做了一些和gnn相关的工作,经常听到GCN 和 embedding 相关技术,感觉很是困惑,所以写下此博客,对相关知识进行索引和记录: 参考链接: https://www.toutiao.com/ ...

  9. 【JZOJ4805】【NOIP2016提高A组模拟9.28】跟踪

    题目描述 输入 输出 样例输入 4 2 1 3 1 2 2 3 3 4 样例输出 2 数据范围 解法 预处理出两个陌生人走到各个点的距离. 从石神处开始dfs,判断走到每一个点是否会被抓: 如果会,则 ...

  10. ELK4之进阶学习

    1.精确查找和模糊查找(term和match的区别) match经过分析(analyer)的, term是不经过分词,直接去倒排索引中查找精确的值. 2.建议器的简介(最左前缀或者自带的做) (1)直 ...