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 ...
随机推荐
- svn基本命令使用
1.svn help:可以通过该命令查看svn的所有操作命令,包括命令的缩写 2.首先需要从svn库中checkout对应的项目: (1)svn项目路径为svn://192.168.1.1/mypro ...
- arcgis显示经纬度
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- WPF ScrollViewer嵌套Listbox无法滚动
最近在做项目的时候,发现listBoxzi自带的垂直滚动条有问题,经常在Add(item)的时候下面会多出一些空白的部分,而且滚动条的长度也是无规则的,一会大一会小,而且无法控制横竖滚动条的显隐藏,并 ...
- Python数据分析与展示[第三周](pandas数据特征分析单元8)
数据理解 基本统计 分布/累计统计 数据特征 数据挖掘 数据排序 操作索引的排序 .sort_index() 在指定轴上排序,默认升序 参数 axis=0 column ascending=True ...
- 记一次goland的包导入问题
昨天把go的GOPATH环境变量设置成了“/home/mi/app/gopath”,今天用goland新建的项目在/home/mi/go/src目录下,名字是studygolang,如下图. 结果导入 ...
- Linux之Shell1
1.输出命令:echo echo [选项] [输出内容] : -e 支持反斜线控制的字符转换.(类似于C语言的\) \\ 输出\本身 \t Tab键 \n 换行符 \f 换页符 ...
- 移动项目到centos中运行报错:failed to open stream: Permission denied
这是文件夹没有读写权限的错误: (注意:TP5.0权限给runtime文件夹就行了,官方文档在安装tp5的方法中有介绍到权限问题) 在需要赋予权限的文件夹的前一级输入: chmod -R 文件夹名字
- 【JZOJ4772】【NOIP2016提高A组模拟9.9】运输妹子
题目描述 小轩轩是一位非同一般的的大农(lao)场(si)主(ji),他有一大片非同一般的农田,并且坐落在一条公路旁(可以认为是数轴),在他的农田里种的东西也非同一般--不是什么水稻小麦,而是妹子. ...
- oracle-12333错误
Errors in file /oracle/OraHome1/admin/hndw/udump/hndw_ora_17941.trc: ORA-00600: internal error code, ...
- 洛谷1602 Sramoc问题
刚看到这道题的时候感觉像spfa. 然后发现其实bfs就可以做了. //Serene #include<algorithm> #include<iostream> #inc ...