如何在字符串理论上使用C语言解决问题? [英] How do I solve a problem using C language on string theory?

查看:102
本文介绍了如何在字符串理论上使用C语言解决问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入



输入由两行组成。第一行包含整数n(1 n 100)。第二行包含n个整数a1; a2 ;;;; an(1 ai 100)。其描述如下的字符串。该字符串以a1引号字符开头,后跟bt正数非引号字符,后跟a2引号字符,后跟正数非引号字符,依此类推,直到字符串结束带引号字符。



输出



显示最大数字k,使得字符串由输入是k-quotation。如果没有这样的k,则不显示报价。



我尝试了什么:



我很困惑如何解决这个问题?

Input

the Input consists of two lines. The first line contains an integer n(1 n 100). The Second line contains n integers a1;a2;;;;an(1 ai 100).which describes a string as follows. The string starts with a1 quote characters, which are followed bt a positive number of non-quote characters, which are followed by a2 quote characters, which are followed by a positive number of non-quote characters, and so on, until the string ends with an quote characters.

Output

Display the largest number k such that a string described by the input is a k-quotation. If there is no such k, display no quotation instead.

What I have tried:

I am confuse how to solve this?

推荐答案

您必须首先获取并解析变量的输入,然后运行算法和输出。



对于简单的数据输入,您可以使用 scanf



对于搜索字符串,使用的函数是strtok。这是一些小的教程。这是一个小小的旧学校功能,所以花点时间了解其用法。



下一个需要的功能是atoi。这里有一些教程



你会需要这样的代码

You must at first fetch and parse the input for your variables and than run your algorithm and output.

For simple data input you can use scanf.

For searching into strings the used function is strtok. Here is some small tutorial. It is a little weired "old school" function, so take time to understand the usage.

The next needed function is atoi. Here is some tutorial.

you will need code like this
int value = 0;
value = atoi( szTokBuffer );


你的strtok循环中的


in your strtok loop.


这篇关于如何在字符串理论上使用C语言解决问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆