我是python的新手.这是我的wiered python代码,适用于所有输入,除了
当c = 0且r!= 0时.
我有多个测试用例(tc),r和c作为输入,根据条件给出所需的输出.
问题---输入r = 4&c = 0时,输出应为2,但输出为1.我为每个r!= 0&c = 0做出了错误的答案.
码:
tc=int(input())
while tc:
r,c=raw_input().split()
if int(r)%2==0 and r!=2 and r!=0 and c!=0:
r=int(r)/2
elif r!=2 and r!=0 and c!=0:
r=int(r)/2+1
elif r==0 or r ==2:
r=1
if r!=0:
if int(c)!=0:
print(int(r)*int(c))
else :
if int(r)%2==0 :
print(int(r)/2)
else:
r=int(r)/2+1
print(r)
else :
print(c);
tc=tc-1
Run Code Online (Sandbox Code Playgroud)
样本输入和输出
4 //tc
10 10 //r=10 c= 10
50 //fine
3 3 //r=3 c=3
6 //fine
4 0 //r=4 c=0 …Run Code Online (Sandbox Code Playgroud) 当我使用jQuery UI输入功能时,单击按钮时,它会提交/刷新整个网页.如何停止/取消整个网络以重新加载?
<input style='width:65px;' type='button' class='ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all Bags' id='Buy' name='".$idn."' value='Buy Bags'>
Run Code Online (Sandbox Code Playgroud)
是这样的:
$('.Bags').click(function(){
var $a = $(this).val();
var $b = $(this).attr('id');
var $c = $(this).attr('name');
/* input/button is the issue, how do i stop the form from refreshing? */
});
Run Code Online (Sandbox Code Playgroud)
提前致谢!
编辑
在这里/那里学到一些东西之后,找到了另一种简单的方法来做到这一点,有些人可能不同意,但它到目前为止有效:
<input style='width:65px;' type='button' class='Bags' id='Buy' name='".$idn."' value='Buy Bags' onclick='return false;'>
Run Code Online (Sandbox Code Playgroud)
通过添加" onClick ='返回false;' "将阻止表单刷新/重新加载.
如何通过python读取两行中输入的两个值到两个变量,例如%d%d in c raw_input读取该行中的所有内容
例如1 0
我想要1英寸x和0英寸y
现在我有两种类型:
type Rating = (String, Int)
type Film = (String, String, Int, [Rating])
Run Code Online (Sandbox Code Playgroud)
我有一个包含此数据的文件:
"Blade Runner"
"Ridley Scott"
1982
("Amy",5), ("Bill",8), ("Ian",7), ("Kevin",9), ("Emma",4), ("Sam",7), ("Megan",4)
"The Fly"
"David Cronenberg"
1986
("Megan",4), ("Fred",7), ("Chris",5), ("Ian",0), ("Amy",6)
Run Code Online (Sandbox Code Playgroud)
我怎样才能查看将所有条目存储到FilmDatabase = [Film]之类的文件?
如果输入在1-100之间,如何检查HTML5?
<input type="numeric" name="count" pattern="[1-9]" />
Run Code Online (Sandbox Code Playgroud) 我的用例是这样的:我有几个input:
<label class="minilabel">Field1</label><input type="text">
...
<label class="minilabel">FieldN </label><input type="text">
Run Code Online (Sandbox Code Playgroud)
我必须得到value每个input,然后通过AJAX(post请求)发送它.通常我设置ID为每个input然后我通过$("#id1").val().. 检索它$("#idN").val(),但它是如此错综复杂.有另一种获得这些价值的方法吗?
当我学习Java时,我有这个程序我搞乱了:
package com.nathan2055.booksamples;
import static java.lang.System.out;
import java.util.Scanner;
/**
* @author Nathan2055
*/
public class Copycat {
private static Scanner keyboard;
/**
* @param args
*/
public static void main(String[] args) {
keyboard = new Scanner(System.in);
out.println("This program will copy whatever you type.");
out.println("Please enter a phrase:");
String inputPhrase = keyboard.next();
out.println();
out.println(inputPhrase);
}
}
Run Code Online (Sandbox Code Playgroud)
但是有一个问题.如果你运行它并输入一个带空格的短语,它只会将字符串保存到空格中.如何保存整个字符串呢?
我刚开始学习c#,我正在尝试创建一个控制台应用程序,它将读取文本文件并在命令提示符下显示它.我也试图在单独的dll中创建读取文本文件的方法,因为我计划稍后扩展我的程序并尝试制作一种基于文本的游戏引擎.无论如何,这是我的dll中的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace EngineFeatures
{
public class txtedit
{
public string Write_txt(string textin, out String output)
{
try
{
using (StreamReader sr = new StreamReader(textin))
{
String line = sr.ReadToEnd();
output = line;
return output;
}
}
catch (Exception e)
{
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
就像我是初学者一样,我刚刚开始3天前.无论如何我想做的是能够调用函数EngineFeatures.txtedit.Write_txt("TXT/test.txt"); 在应用程序本身并让它返回一个字符串,但我仍然有点困惑,我也得到一个错误说"EngineFeatures.txtedit.Write_txt(string,out string)':并非所有代码路径都返回一个值." 我究竟做错了什么?
所以我试图让用户输入他们的名字和身高.
我有其他代码.
我有这个.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int name1;
cout << "What's your name?";
cin >> name1;
int height1;
cout << "What's your height?";
cin >> height1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是它不允许用户输入他们的身高.有任何想法吗?
我有用于输入文件并将内容存储在字符串中的函数.
这是代码
std::string inputFile();
int main()
{
std::string fileContents = inputFile();
}
std::string inputFile()
{
std::string fileName;
std::cout << "\nEnter file name, including path:\n";
std::getline(std::cin, fileName);
std::ifstream input(fileName.c_str());
std::string buffer;
std::string result;
if (!input.fail()) // if input does not fail
{
while (!input.eof())
{
std::getline(input, buffer);
result.append(buffer);
}
input.close();
return result;
}
else
{
std::cout << "\nInvalid file name or path";
inputFile(); // recursive call to inputFile
}
}
Run Code Online (Sandbox Code Playgroud)
如果正确输入文件名和路径,它工作正常.
但是,如果输入的文件名或路径不正确,则会执行对inputFile的递归调用,并为用户提供另一个输入文件的机会.然后,如果正确输入文件名,则Visual Studio 2013中会引发错误:
"Assignment4.exe中0x77F7A9E8(msvcr120d.dll)的未处理异常:0xC0000005:访问冲突读取位置0xCCCCCCC0."
谢谢你的任何建议