int main()
{
int numbers[30];
int i;
// making array of 30 random numbers under 100
for(i=0;i<30;i++)
{
numbers[i] = rand() % 100;
}
// finding the greatest number in the array
int greatest = 0;
srand(1);
for(i=0;i<30;i++)
{
if ( numbers[i] > greatest)
greatest = numbers[i];
}
Run Code Online (Sandbox Code Playgroud)
那我怎么告诉程序显示数组的最大值?谢谢
我的xml文件的测试样本如下所示:
的test.xml
<feed>
<entry>
<title>Link ISBN</title>
<libx:libapp xmlns:libx="http://libx.org/xml/libx2" />
</entry>
<entry>
<title>Link Something</title>
<libx:module xmlns:libx="http://libx.org/xml/libx2" />
</entry>
</feed>
Run Code Online (Sandbox Code Playgroud)
现在,我想编写一个xquery,它将找到所有<entry>具有<libx:libapp>子元素的元素.然后,对于所有这样的条目,如果标题包含给定的关键字(例如链接),则返回标题.因此,在我的示例xml文档中,xquery应该返回"Link ISBN".
我的示例xquery如下所示:
samplequery.xq(此处doc_name是上面显示的xml文件,libapp_matchkey是关键字,例如'Link')
declare namespace libx='http://libx.org/xml/libx2';
declare variable $doc_name as xs:string external;
declare variable $libpp_matchkey as xs:string external;
let $feeds_doc := doc($doc_name)
for $entry in $feeds_doc/feed/entry
(: test whether entry has libx:libapp child and has "Link" in its title child :)
where ($entry/libx:libapp and $entry/title/text()[contains(.,$libapp_matchkey)])
return $entry/title/text()
Run Code Online (Sandbox Code Playgroud)
此xquery返回null而不是预期的结果'Link ISBN'.这是为什么?
标题几乎说明了一切。我需要使用 VB6 获取一些硬件信息,例如 CPU 信息和总 RAM。理想情况下,它会为 CPU 返回类似以下内容:
英特尔酷睿 2 四核 Q8500 2.66 GHz
对于 RAM,一些简单的东西,例如计算机总共拥有的 MB 量的整数。
我有一个类(如下所示)扩展JPanel并包含一个JTextPane.我想重定向System.out和System.err我JTextPane.我的班级似乎没有用.当我运行它时,它确实重定向系统打印,但它们不打印到我的JTextPane.请帮忙!
注意:仅在应用程序启动时重定向调用.但是在发布后的任何时候,System.out呼叫都不会被重定向到JTextPane.(即,如果我System.out.prinln();在类中放置一个,它将被调用,但是如果它被放置在以actionListener供以后使用,则它不会重定向).
public class OSXConsole extends JPanel {
public static final long serialVersionUID = 21362469L;
private JTextPane textPane;
private PipedOutputStream pipeOut;
private PipedInputStream pipeIn;
public OSXConsole() {
super(new BorderLayout());
textPane = new JTextPane();
this.add(textPane, BorderLayout.CENTER);
redirectSystemStreams();
textPane.setBackground(Color.GRAY);
textPane.setBorder(new EmptyBorder(5, 5, 5, 5));
}
private void updateTextPane(final String text) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Document doc = …Run Code Online (Sandbox Code Playgroud) 我希望我的应用程序识别相机拍摄的条形码.可以使用Android SDK吗?
像这样: 条形码扫描仪
为什么第一次调用someMethod没有明确表示它是String []?
可以使用数组初始值设定项创建String []数组,但不能使用它来传递参数.花括号是否以某种其他方式用于传递参数,这些参数会破坏我对此行为的看法?
public void someMethod(String[] arr){
//do some magic
}
public void makeSomeMagic(){
String[] arr = {"cat", "fish", "cow"};
//Does not compile!
someMethod({"cat", "fish", "cow"});
//This compiles!
someMethod(new String[]{"cat", "fish", "cow"});
//This compiles!
someMethod(arr);
}
Run Code Online (Sandbox Code Playgroud)
编译器错误如下:
Moo类型中的方法someMethod(String [])不适用于参数(String,String,String)
我想知道是否有办法解决这个问题
var string = "foo::bar"
Run Code Online (Sandbox Code Playgroud)
获取字符串的最后一部分:"bar"使用正则表达式.
我试图做好预测,但却无法掌握它们做到这一点.
-
UPDATE
也许一些例子会使问题更加清晰.
var st1 = "foo::bar::0"
match should be 0
var st2 = "foo::bar::0-3aab"
match should be 0-3aab
var st3 = "foo"
no match should be found
Run Code Online (Sandbox Code Playgroud) 所有,
我试图识别带有Mac行结尾的纯文本文件,并在InputStream中静默地将它们转换为Windows或Linux行结尾(重要的部分是LF字符,真的).具体来说,我正在使用几个采用InputStreams的API,并且很难锁定以寻找\n作为换行符.
有时,我得到二进制文件.显然,一个不像文本的文件不应该进行这种替换,因为碰巧对应于\ r的值显然不能静默地跟随\n而不会严重损坏事物.
我试图使用java.net.URLConnection.guessContentTypeFromStream并仅在类型为text/plain时执行endline转换.不幸的是,"text/plain"它似乎没有回归价值; 我得到的只是null我的平面文本文件,并且假设所有无法识别的文件都可以修改可能并不安全.
我可以使用哪个更好的库(最好是在公共Maven存储库和开源中)来执行此操作?或者,我如何让guessContentTypeFromStream为我工作?我知道我正在描述一个本质上危险的应用程序,并且没有任何解决方案可以完美,但我应该将"null"视为"text/plain",我只需要自己编写更多代码来寻找证据证明它不是"T?
我有6,00,000 entries in MongoDB以下格式:
feature:category:count
Run Code Online (Sandbox Code Playgroud)
哪里
我想缓存前1000个元组,让我们说不要每次都查询数据库.
如何在Python中构建LRU缓存?或者有任何已知的解决方案吗?
当我自己找到解决方案的时候,我以为我会在那里得到这个问题.
在构建了大量应用程序之后,我有最后一分钟的要求来支持读/写一个额外的数据库(总共2个,没有已知的其他数据库).我使用NHibernate构建了应用程序,Autofac提供了DI/IoC组件.FWIW,它驻留在ASP.NET MVC 2应用程序中.
我有一个通用的存储库类,它采用NHibernate会话.理论上,我可以继续使用这个通用存储库(IRepository<>)为第二个数据库,只要传递给它的会话是从适当的SessionFactory生成的,对吧?
好吧,当应用程序启动时,Autofac会做到这一点.关于Session和SessionFactory,我有一个模块说明:
builder.Register(c => c.Resolve<ISessionFactory>().OpenSession())
.InstancePerMatchingLifetimeScope(WebLifetime.Request)
.OnActivated(e =>
{
e.Context.Resolve<TransactionManager>().CurrentTransaction = ((ISession)e.Instance).BeginTransaction();
});
builder.Register(c => ConfigureNHibernate())
.SingleInstance();
Run Code Online (Sandbox Code Playgroud)
返回基本SessionFactory的ConfigureNHibernate()看起来像:
private ISessionFactory ConfigureNHibernate()
{
Configuration cfg = new Configuration().Configure();
cfg.AddAssembly(typeof(Entity).Assembly);
return cfg.Configure().BuildSessionFactory();
}
Run Code Online (Sandbox Code Playgroud)
目前,这仅限于一个数据库.在任何其他NHib场景中,我可能会将单独的SessionFactories的实例推送到哈希中,并根据需要检索它们.我不想重新设计整个事情,因为我们非常接近主要版本.所以,我猜我至少需要修改上面的方法,以便我可以独立配置两个SessionFactories.我的灰色区域是如何指定正确的工厂与特定存储库一起使用(或至少对于特定于第二个数据库的实体).
任何人都有使用IoC容器和NHibernate这种方式的经验吗?
编辑 我已经删除了一个GetSessionFactory方法,它接受一个配置文件路径,检查HttpRuntime.Cache中匹配的SessionFactory的存在,创建一个新实例(如果还没有),并返回该SessionFactory.现在我仍然需要知道如何告诉Autofac如何以及何时指定适当的配置路径.新方法看起来像(比利2006年后大量举债这里):
private ISessionFactory GetSessionFactory(string sessionFactoryConfigPath)
{
Configuration cfg = null;
var sessionFactory = (ISessionFactory)HttpRuntime.Cache.Get(sessionFactoryConfigPath);
if (sessionFactory == null)
{
if (!File.Exists(sessionFactoryConfigPath))
throw new FileNotFoundException("The nhibernate configuration file at '" + sessionFactoryConfigPath + "' could not be found.");
cfg …Run Code Online (Sandbox Code Playgroud)