//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. DesktopLayer.exe专杀

    这两天发现电脑卡慢. 同事电脑发现病毒,而后装上杀软后(一直在裸奔~~~),发现自己电脑也存在. DesktopLayer.exe 会有以下几个行为: 第一,会在C:\Program Files (x ...

  2. 第三十一讲:UML类图(上)

    类名 成员变量:属性 成员函数:方法 访问权限-属性名-属性的类型 访问权限-方法名-返回值,还可以传递参数列表. 继承类的类图 JAVA里面类的访问权限只有两种:package(默认的访问权限)和p ...

  3. LeetCode Top 100 Liked Questions in Golang(updating...)

    leetcode go语言版本,主要为了熟悉下语言 1. Two Sum 双指针版本, O(NlogN) func twoSum(nums []int, target int) []int { val ...

  4. 【Leetcode 堆、快速选择、Top-K问题 BFPRT】有序矩阵中第K小的元素(378)

    题目 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩阵中第k小的元素. 请注意,它是排序后的第k小元素,而不是第k个元素. 示例: matrix = [ [ 1, 5, 9], [ ...

  5. Bootstrap —— tab切换

    tab切换 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  6. RabbitMQ默认端口

    4369 (epmd), 25672 (Erlang distribution)5672, 5671 (AMQP 0-9-1 without and with TLS)15672 (if manage ...

  7. API管理的五大规则

    http://www.csdn.net/article/2012-12-18/2812929-5-Rules-For-API-Management 1. 设计 开发人员使用API访问各种不同的类,并且 ...

  8. Directx11教程(66) D3D11屏幕文本输出(1)

    原文:Directx11教程(66) D3D11屏幕文本输出(1)      在D3D10中,通过ID3DX10Font接口对象,我们可以方便的在屏幕上输出文字信息,一个DrawText函数就能解决所 ...

  9. 笔记:字体大小的几种不同的格式px,em,rem

    px px像素(Pixel),相对长度单位,像素px是相对于显示器屏幕分辨率而言的.(引自CSS2.0手册) 譬如,Windows的用户所使用的分辨率一般是96像素/英寸. 而MAC的用户所使用的分辨 ...

  10. sql函数的使用——系统函数

    n  sys_context 1)terminal:当前会话客户所对应的终端的标识符 2)lanuage:语言 3)db_name:当前数据库名称 4)nls_date_format:当前会话客户端所 ...