Goshko是一位热衷于棋的球员。有一天,他对自己的工作感到厌倦,决定休息一下,用棋盘创造一个游戏。他拿了一根弦,例如" Software University_2345&#34 ;,通过ASCII码将其符号转换为数字,并用它们填充棋盘。他只取大写和小写字母和数字的值。任何其他符号的值为零。他用数字从左到右和从上到下填充了板的方块(参见下面的例子)。棋盘的大小是n * n(例如n = 5)并且它总是以黑色方块开始。 N将永远是一个奇数。
S o f t w
a r e U
n i v e r
s i t y _
2 3 4 5
83 111 102 116 119
97 114 101 0 85
110 105 118 101 114
115 105 116 121 0
50 51 52 53 0
我们假设有两个竞争团队:黑人团队和白人团队。每支球队的得分都是其方格中值的总和。但是如果一个正方形包含一个大写字母,那么它的价值应该给予对方团队。在上面的示例中,分数计算如下:
白队得分 = 83' S' + 111' o' + 116' t' + 97' a' + 101' e' + 105'我' + 101' e' + 115' s' + 116' t' + 51' 3' + 53' 5' = 1049
黑队得分 = 102' f' + 119' w' + 114' r' + 85' U' + 110' n' + 118' v' + 114' r' + 105'我' + 121' y' + 50' 2' + 52' 4' = 1090。
输入 应从控制台读取输入数据。
•第一行包含棋盘的大小n。
•第二行包含输入字符串。
输入数据始终有效且采用所述格式。无需明确检查。
输出 输出应打印在控制台上。
•第一个输出线以格式保存获奖团队:“获胜者是:{name}团队”。
•第二行保留了获胜和失败球队得分之间的差异。
•如果分数相等,请打印“Equal result:{points}”。在这种情况下不要打印差异!
这是我目前的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ChessboardGame
{
class Program
{
static void Main(string[] args)
{
int boardSize = int.Parse(Console.ReadLine());
string inputString = Console.ReadLine();
char[,] board = new char[boardSize, boardSize];
int p = inputString.Length; //check so it doesnt go out of range of the string
int i = 0; //to know which element of the string to store into the matrix
int whiteScore = 0;
int blackScore = 0;
int oddOrEven = 0; //to know if the cell is odd or even
for (int row = 0; row < boardSize; row++) //filling the matrix
{
if (p == 0)
break;
for (int col = 0; col < boardSize; col++)
{
if (p == 0)
break;
board[row, col] = inputString[i];
i++;
p--;
}
}
for (int row = 0; row < boardSize; row++) //calculating score
{
for (int col = 0; col < boardSize; col++)
{
if (oddOrEven % 2 == 0)
{
if (!(((int)board[row, col] >= 65 && (int)board[row, col] <= 90) && ((int)board[row, col] >= 97 && (int)board[row, col] <= 122)))
{
if ((int)board[row, col] >= 65 && (int)board[row, col] <= 90)
{
whiteScore += (int)board[row, col];
}
else
{
blackScore += (int)board[row, col];
}
}
}
else
{
if (!(((int)board[row, col] >= 65 && (int)board[row, col] <= 90) && ((int)board[row, col] >= 97 && (int)board[row, col] <= 122)))
{
if ((int)board[row, col] >= 65 && (int)board[row, col] <= 90)
{
blackScore += (int)board[row, col];
}
else
{
whiteScore += (int)board[row, col];
}
}
}
oddOrEven++;
}
}
if (whiteScore > blackScore)
{
Console.WriteLine("The winner is: white team");
Console.WriteLine(whiteScore - blackScore);
}
else if (blackScore > whiteScore)
{
Console.WriteLine("The winner is: black team");
Console.WriteLine(blackScore - whiteScore);
}
else
{
Console.WriteLine("Equal result: {0}", whiteScore);
}
}
}
}
我的答案错了。
我输入
5 软件大学_2135
我希望
获胜者是:黑队 41
但我收到了
获胜者是:白队 22
我无法弄明白。我一直试图改变球队的位置。此外,我认为我的表达方式可能有问题,因为查看天气信件是不是资本。
答案 0 :(得分:0)
我在你的循环中做了一些改变:
describe("image-upload view", function () {
before(function () {
// create test fixture
this.$fixture = $('<div id="image-view-fixture"></div><div>');
});
beforeEach(function () {
// fake image
this.b64DataJPG = '/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAASUkqAAgAAA' +
'ABABIBAwABAAAABgASAAAAAAD/2wBDAAEBAQEBAQEBAQEBAQEB' +
'AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ' +
'EBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB' +
'AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ' +
'EBAQEBAQH/wAARCAABAAIDASIAAhEBAxEB/8QAHwAAAQUBAQEB' +
'AQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBA' +
'QAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAk' +
'M2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1' +
'hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKj' +
'pKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+' +
'Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAA' +
'AAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAx' +
'EEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl' +
'8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2' +
'hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmq' +
'srO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8v' +
'P09fb3+Pn6/9oADAMBAAIRAxEAPwD+/iiiigD/2Q==';
var b64toBlob = function (b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var input = b64Data.replace(/\s/g, '');
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
try{
var blob = new Blob( byteArrays, {type : contentType});
}
catch(e){
// TypeError old chrome and FF
window.BlobBuilder = window.BlobBuilder ||
window.WebKitBlobBuilder ||
window.MozBlobBuilder ||
window.MSBlobBuilder;
if(e.name == 'TypeError' && window.BlobBuilder){
var bb = new BlobBuilder();
bb.append(byteArrays);
blob = bb.getBlob(contentType);
}
else if(e.name == "InvalidStateError"){
// InvalidStateError (tested on FF13 WinXP)
blob = new Blob(byteArrays, {type : contentType});
}
else{
// We're screwed, blob constructor unsupported entirely
}
}
return blob;
};
this.blobJPG = b64toBlob(this.b64DataJPG, "image/jpg");
/* **************** */
this.$fixture.empty().appendTo($("#fixtures"));
this.view = new imageUpLoad({
file: this.blobJPG,
cb: function (url) {console.log(url);},
maxFileSize: 500000,
minWidth: 200,
maxHeight: 900,
maxWidth: 1000,
maxAllowedHeight: 4300,
maxAllowedWidth: 1000
});
this.renderSpy = sinon.spy(this.view, "render");
this.readFileDataStub = sinon.stub(this.view, 'readFileData');
this.resizeImageStub = sinon.stub(this.view, 'resizeImage');
this.returnDataUrlStub = sinon.stub(this.view, 'returnDataUrl');
this.mainFnSpy = sinon.spy(this.view, 'mainFn');
this.transformImgStub = sinon.stub(this.view, 'transformImg');
this.sizeConfigStub = sinon.stub(this.view, 'sizeConfig');
this.resizeConfStub = sinon.stub(this.view, 'resizeConf');
this.callbackSpy = sinon.spy();
});
afterEach(function () {
this.renderSpy.restore();
this.readFileDataStub.restore();
this.resizeImageStub.restore();
this.returnDataUrlStub.restore();
this.mainFnSpy.restore();
this.sizeConfigStub.restore();
this.resizeConfStub.restore();
this.transformImgStub.restore();
});
after(function () {
$("#fixtures").empty();
});
it("can render", function () {
var _view = this.view.render();
expect(this.renderSpy).to.have.been.called;
expect(this.view).to.equal(_view);
});
});
它现在就像一个魅力。问题是你检查的方式是char是否有效。 for (int row = 0; row < boardSize; row++) //calculating score
{
for (int col = 0; col < boardSize; col++)
{
char c = board[row, col];
if (oddOrEven % 2 == 0)
{
if (char.IsLetterOrDigit(c))
{
if (char.IsUpper(c))
{
whiteScore += c;
}
else
{
blackScore += c;
}
Console.WriteLine(c);
}
}
else
{
if (char.IsLetterOrDigit(c))
{
if (char.IsUpper(c))
{
blackScore += c;
}
else
{
whiteScore += c;
}
Console.WriteLine(c);
}
}
oddOrEven++;
}
}
框架中充满了有用的工具,请不要犹豫使用它们。在这里,我只使用.Net
来拯救你。