两道UVaOJ(489、490)ACM疑问求解~ 为什么不能AC?

neicole neicole 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
表示很悲剧地说,一道未想到,另外一道的问题又来了..
输入输出怎么看都与Example的一样,然后,看了网上几个例子,思路也基本一致,但是就是不能AC~ 
有注释,有分析思路,求大侠为我看一下程序~

490_RotatingSentences.cpp
// 490_RotatingSentences.cpp

/**
490 - Rotating Sentences
Time limit: 3.000 seconds

Rotating Sentences
In ``Rotating Sentences,'' you are asked to rotate a series of input sentences 90 degrees clockwise.
So instead of displaying the input sentences from left to right and top to bottom,
your program will display them from top to bottom and right to left.

Input and Output
As input to your program, you will be given a maximum of 100 sentences, each not exceeding 100 characters long.
Legal characters include: newline, space, any punctuation characters, digits, and lower case or upper case English letters.
(NOTE: Tabs are not legal characters.)
The output of the program should have the last sentence printed out vertically in the leftmost column;
the first sentence of the input would subsequently end up at the rightmost column.

Sample Input
Rene Decartes once said,
"I think, therefore I am."

Sample Output
"R
Ie
n
te
h
iD
ne
kc
,a
r
tt
he
es
r
eo
fn
oc
re
e
s
Ia
i
ad
m,
.
"
**/

/**
* 题目分析:
* 这题的题目要求(90 degrees clockwise)将输入的字符组顺时针旋转90度,
* 思路很简单,定义二维数组,输入的时候 先行->后列 输入,输出的时候 先列 -> 后行 输出。
* 下面程序采用了获取字符保存于二维字符数组,然后再将二维数组中的字符提取输出的方法。
* 在输入二组数组的同时,还对数组的行列大小做了一个记录,
* 使用lineMaxNumber记录一行里面最大的列数(此时不含下标0),这样,就可以减少输出时循环的次数,
* 使用rowArray[]记录每一行的列数,当顺时针90度输出时,将列数与这个每行的列数比较,当其超过记录数,输出空格。
* 使用rowMax记录总行数(含0下标),这样就可以知道整个矩阵的大小了,方便输出的时候可以从最后行开始输出。
**/


#include <cstdio>
using namespace std;

char cArray[120][120];
int rowArray[120] = {0};
int lineMaxNumber = 0;

int main()
{
int row = 0;
int column = 0;
char c;
while(EOF != (c = getchar())){
// if ('\\' == c) break;
if ('\n' == c){ // 遇上换行符时
column = 0; // 列数清零
++row; // 行数加1
}
else{
cArray[row][column++] = c;
++rowArray[row]; // 记录行的字符数(一行有多少列元素)
if (rowArray[row] > lineMaxNumber){
lineMaxNumber = rowArray[row];
}
}
}
const int rowMax = row; // 记录最大行数(这里包含了下标0)
// 开始timewise(顺时针)旋转90度输出
for (int column = 0; column < lineMaxNumber; ++column){
for (row = rowMax; row >= 0; --row){
c = column < rowArray[row] ? cArray[row][column]: ' ';
// c = !cArray[row][column] ? ' ': cArray[row][column];
printf("%c", c);
}
printf("\n");
// printf("BBB\n");
}
return 0;
}


// 489_HangmanJudge.cpp

/**
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting Started
489 - Hangman Judge
Time limit: 3.000 seconds

Hangman Judge
In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games.
For each game, the answer to the puzzle is given as well as the guesses.
Rules are the same as the classic game of hangman, and are given as follows:
1. The contestant tries to solve to puzzle by guessing one letter at a time.
2. Every time a guess is correct, all the characters in the word that match the guess will be ``turned over.''
For example, if your guess is ``o'' and the word is ``book'', then both ``o''s in the solution will be counted as ``solved.''
3. Every time a wrong guess is made, a stroke will be added to the drawing of a hangman, which needs 7 strokes to complete.
Each unique wrong guess only counts against the contestant once.
4. ______
5. | |
6. | O
7. | /|\
8. | |
9. | / \
10. __|_
11. | |______
|_________|
12. If the drawing of the hangman is completed before the contestant has successfully guessed all the characters of the word,
the contestant loses.
13. If the contestant has guessed all the characters of the word before the drawing is complete,
the contestant wins the game.
14. If the contestant does not guess enough letters to either win or lose, the contestant chickens out.
Your task as the ``Hangman Judge'' is to determine, for each game, whether the contestant wins, loses, or fails to finish a game.

Input
Your program will be given a series of inputs regarding the status of a game. All input will be in lower case.
The first line of each section will contain a number to indicate which round of the game is being played;
the next line will be the solution to the puzzle; the last line is a sequence of the guesses made by the contestant.
A round number of -1 would indicate the end of all games (and input).

Output
The output of your program is to indicate which round of the game the contestant is currently playing as well as the result of the game.
There are three possible results:
You win.
You lose.
You chickened out.

Sample Input
1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
-1

Sample Output
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
**/

/**
* 题目大意:
*   先输入第几回合(改变一下格式输出,对计算无影响),再输入两个单词,假设第一个单词叫做first,
* 第二个单词叫做second,那么,将second中的每个字符与first比较,假如,second单词能从下标最小到最大
* 与first中的单词字符比较:
* 1. 不管是first还是second,只要有重复的字符,都不列入比较次数内。
* 2. 假如在比较过程中,比较了七次或以上还是没有将first的全部字符比较出来(即second中有first中的全部字母)。
* 那么,就输出 You lose.
* 3. 如果在七次内,将全部字符比较出来,就输出You win.
* 4. 如果在七次内,但又未将first中的全部字符比较出来,second就遍历完了,那么就输出 You chickened out.
*
* 题目分析:
* 1. 先按要求,输入三个数据,int, string1, string2;
* 2. 去除string1和string2的重复字母。
* 3. 将string2中的字符(从下标最小到最大)逐个与string1中的字符比较,查看是否有相同字符。
* 存在相同字符:win计数加1, 如果win达到string1的长度,输出 You win. 退出该循环,继续下一轮比赛。
* 没有相同字符:lose计数加1,如果lose达到7,输出 You lose.通出循环,继续下一轮比赛。
* 4. 比较结束后,还会有一种情况,当win计数未达string1的长度且lose计数小于7时,输出 You chickened out.
* 5. 注意:当round == -1 时,结束程序。
**/

#include <string>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
int round;
while(scanf("%d", &round) && round != -1){
printf("Round %d\n", round); // 按题目要求,打印“第几轮比赛”
string hangman;
string contestant;
cin >> hangman >> contestant; // 继续输入,两个字符串

string deleteTheSameInString(string); // 删除重复字符
hangman = deleteTheSameInString(hangman);
contestant = deleteTheSameInString(contestant);

const int nh = hangman.length();
const int nc = contestant.length();

int winCount = 0;
int loseCount = 0;
for(int i = 0; i < nc; ++i){
bool noSame = true;
for (int j = 0; j < nh; ++j){ // contesant的单个字母与hangman内的全部字符比较
if (contestant[i] == hangman[j]){
if (++winCount == nh){
printf("You win.\n");
}
noSame = false;
break;
}
}
if (noSame){
if(7 <= ++loseCount){ // 超出猜的机会
printf("You lose.\n");
break;
}
}
}
if (winCount != nh && 7 > loseCount){ // 未全部猜出而且还有猜的机会
printf("You chickened out.\n");
}
}
return 0;
}

string deleteTheSameInString(string source)
{
string copyString;
int n = source.length();
for (int i = 0; i < n; ++i){
if(' ' != source[i]){ // 非空白字符则将其加入字符串
copyString.push_back(source[i]);
}
else{
continue; // 发现空白字符,可以继续下一轮的循环
}
int copyStringLastIndex = copyString.length() - 1;
for (int j = i + 1; j < n; ++j){
if (copyString[copyStringLastIndex] == source[j]){
source[j] = ' '; // 发现重复的字符则将其换为' '
}
}
}
return copyString;
}
...全文

相关推荐

ACM/ICPC_uva动态规划题列表

ACM UVA 动态规划 文档里有UVAOJ上面大量的DP练习题,可以说认真做完之后,你的DP不是问题。

Algorithm_Empire

【数据结构和算法】如何学习数据结构与算法 ?过来人的建议(二)【方法篇】

上一篇:如何学习数据结构与算法?过来人的建议!!!(一)【方法篇】对如何打基础进行了介绍,接下来就应该是实践的提升啦!赶紧看一下吧! 一、实践提升 实践提升可以通过许多的方法,比如:做项目,做练习题等。 我认为最实用、最直接、最快速的方法就是刷 ACM 算法题目,每个题目都会针对一个或多个算法进行考察,每道题目后台数据量足够大,可信度高。 温馨提示:在做题过程中遇到不会/不懂的知识点要学习总结哦!可以通过写博客的形式记录自己的成长。 下面就推荐几个OJ,大家可以去上面做题: 北京大学 PO.

Muti-Agent

leetcode下载-Qu.Code:问题代码

leetcode下载 题库 开刷日期: 2015-06-15号,开始刷 leetcode 和 lintcode 网上的题库 PKU Online Judge-题库中有大量的题目-【北京大学】-【多语言版】【POJ】 http://poj.org Sphere Online Judge-允许使用各种各样的编程语言【SPOJ】 http://www.spoj.pl/ SGU Online Contester-具有模拟参加历史比赛的虚拟赛功能 http://acm.sgu.ru/ Codeforces-不断维护历届题库 http://codeforces.com 首先,要向读者介绍的是历史最悠久,最著名的OJ-西班牙Valladolid大学的【UVaOJ】 http://uva.onlinejudge.org/ 【被墙了,MD,而本书每章后面大量的习题都是要到这个网站上去做的】 第2个要介绍的是浙江大学的【ZOJ】 http://acm.zju.edu.cn/ 【只有英文,不支持其他语言显示】 1. leetcode: Problems | LeetCode

weixin_38706197

基于统一环境建模与可行性约束一致化的三维路径规划A星RRT星与粒子群优化对比研究(Matlab代码实现)

内容概要:本文系统研究了基于统一环境建模与可行性约束一致化的三维路径规划问题,对A*算法、RRT*算法与粒子群优化(PSO)算法在三维空间中的路径规划性能进行了深入对比分析。通过构建标准化的仿真环境与统一的可行性约束条件,从路径长度、规划耗时、避障能力及路径平滑性等多个维度对三种算法进行定量评估,全面揭示其各自的优势与局限性。研究旨在为不同应用场景下的路径规划算法选型提供科学依据与技术指导,并配套提供了完整的Matlab代码实现,便于读者复现结果与进一步研究。; 适合人群:具备一定算法基础和Matlab编程能力,从事机器人、自动驾驶、无人机或智能系统等相关领域研究的研发人员及研究生。; 使用场景及目标:① 掌握A*、RRT*、PSO等主流路径规划算法的核心思想与实现细节;② 学习如何在统一标准下对不同算法进行公平、有效的性能对比与评估;③ 获取可直接用于科研或项目开发的三维路径规划Matlab代码框架。; 阅读建议:建议读者在阅读过程中结合提供的Matlab代码进行实践操作,通过修改环境参数和算法配置来观察不同算法的表现差异,从而加深对算法原理与适用场景的理解。

茜姐_博客

YOLO26算法城市道路车辆与行人目标检测+训练好的模型+261张数据集+pyqt可视化界面.zip

附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[路障(barrier), 自行车(bicycle), 公交车(bus), 小汽车(car), 施工车辆(construction_vehicle), 摩托车(motorcycle), 行人(pedestrian), 交通锥(traffic_cone), 拖车(trailer), 卡车(truck)] · 总计:261 张 · 测试集:44 张 · 验证集:146 张 · 训练集:71 张 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 92 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.1446** mAP50-95 | 0.0706 Precision | 0.4273 Recall | 0.1741 train/box_loss | 2.0121 train/cls_loss | 2.1335 val/box_loss | 2.1985 val/cls_loss | 2.2913 【训练过程分析】 这轮训练从一开始就没有给我太多惊喜。训练曲线显示,train/box_loss 和 train/cls_loss 都在前 40 轮快速下降,这让我一度觉得模型很快就能收敛,然而后续的曲线却让我感到有些无奈。从第 41 轮开始,train/box_loss 只是在缓慢下降,而 train/cls_loss 则一直保持在一个较高的水平,这表明模型在... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。

guo_xiao_xiao_
评论 4
收藏 已收藏
分享
返回顶部
neicole
数据结构与算法 33,027 成员 35,334 内容