谁会做这道c语言竞赛编程题目的题目?

谁会这道C语言的题目呀?_百度知道您的举报已经提交成功,我们将尽快处理,谢谢!
一楼的回答不对啊,你求的是最小公约数而不是最小公倍数,两个整数的最小公约数永远是1,应该这样改:
int x,y,a,m,n,t;
大家还关注
有什么软件可以将windows7直接更新...求大神帮忙看上这道题 - C语言当前位置:& &&&求大神帮忙看上这道题求大神帮忙看上这道题&&网友分享于:&&浏览:10次求大神帮忙看下这道题1. 编程实现在一个9位数的正整数n中插入4个乘号,使分得的5个整数的乘积最大;2. 输入 n3. 输出 被分得的5个整数、得到的最大乘积4. 例如:输入
输出 73*401*9*8*62= & 算法上怎么实现,或者给点思路吧,谢谢!------解决方案--------------------
分解n为9个数字存入数组的第0--第8个元素中最大乘积设为max=0五个整数全设为0第一个乘号的位置p1在第1--第5元素前(循环){p1前的元素连乘拼合第一个整数第二个乘号的位置p2在p1+1--第6元素前(循环){p2前的元素拼合为第二个整数第三个乘号的位置p3在p2+1--第7元素前(循环){p3前的元素拼合为第三个整数第四个乘号的位置p4在p3+1--第8元素前(循环){p4前的元素拼合为第四个整数 p4前的元素拼合为第五个整数 五个整数的乘积记为product 若product&max {max&=product
并记录五个整数
}}}}}输出max和记录的五个整数
------解决方案--------------------
只拿原题目中的数据做测试。/*******************************************1. 编程实现在一个9位数的正整数n中插入4个乘号,使分得的5个整数的乘积最大;2. 输入 n3. 输出 被分得的5个整数、得到的最大乘积4. 例如:输入
输出 73*401*9*8*62= &**********************************************/& #include &stdio.h&#include &stdlib.h&int getInteger( int a[], int start, int last){
int product=a[start];
for( k=start+1; k& k++)
product=product*10+a[k];}& int main(int argc, char *argv[]){
int a[9]={ 7, 3, 4, 0, 1, 9, 8, 6, 2 };//原题目数据
int product=1;
int max=0;
int maxb[5];&
int p1,p2,p3,p4;&
for(p1=1; p1&6; p1++)
b[0]= getInteger(a, 0, p1);&
for(p2=p1+1; p2&7; p2++)
b[1]= getInteger(a, p1, p2);
for( p3=p2+1; p3&8; p3++ )
b[2]= getInteger(a, p2, p3);
for(p4=p3+1; p4&9; p4++)
b[3]=getInteger(a, p3, p4);
product=b[4]=getInteger(a, p4, 9);
for(k=0; k&4; k++)
product*=b[k];
if( product&max )
for( k=0;k&5; k++ )&
maxb[k]=b[k];
printf(&\n Max is %d = %d&,max,maxb[0]) ;&
for( k=1; k&5; k++ )
printf(& * %d&,maxb[k]);&
printf(&\n&);
system(&PAUSE&);
return 0;}
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有君,已阅读到文档的结尾了呢~~
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
10道C语言题
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
白手起家, 积分 5, 距离下一级还需 195 积分
论坛徽章:0
今天参加某司的笔试,要求用C语言实现下面这道题:
把数据读入比较字符串string[],然后读入一个模式字符串,要求查找string[]中和模式字符串的所有匹配,输出行号、匹配字符串。匹配时不区分大小写,并且可以有一个用中括号表示的模式匹配。如&aa[123]bb&, 就是说aa1bb, aa2bb, aa3bb都算匹配。
以下是实例,输入格式如下
4& & //要输入的比较字符串行数
Aab&&//比较字符串
a[a2b]b& &//模式字符串
其中,1,2,4是输入时的比较字符串行号
对于这道题,我感觉就是加了中括号里的模式匹配不好解决,没想到好的办法,当时想了半天都不知所措,请大家给点意见
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
论坛徽章:88
justcoding
& & 允许用正则库么?
丰衣足食, 积分 540, 距离下一级还需 460 积分
论坛徽章:7
如果只有简单的[]里面没其他表达式的话,简单想法直接开一条链表记录整个表达式,碰到[]这种就再建一个子链表把可能的值串起来。struct {
& & struct list *
& &
& & union {
& && &&&
& && &&&
& & }
};复制代码或者用自动状态机吧
腰缠万贯, 积分 9159, 距离下一级还需 841 积分
论坛徽章:14
随手写一个,不知道对不对#include &stdbool.h&
#include &ctype.h&
bool match( const char* s, const char* t )
{
& & for( ; *s && *t; ++s,++t )
& & {
& && &&&if( *t == '[' )
& && &&&{
& && && && &for( ++t; *t && *t!=']' && tolower(*s)!=tolower(*t); ++t );
& && && && &if( *t=='\0' || *t==']' )
& && && && && &
& && && && &for( ; *t && *t!=']'; ++t );
& && &&&}
& && &&&else if( tolower(*s)!=tolower(*t) )
& && && && &
& & }
& & return !*s && !*t;
}
#include &stdio.h&
int main( void )
{
& & printf( &%s\n&, match(&Aab&,&a[a2b]b&)?&true&:&false& );
& & printf( &%s\n&, match(&a2B&,&a[a2b]b&)?&true&:&false& );
& & printf( &%s\n&, match(&ab&,&a[a2b]b&)?&true&:&false& );
& & printf( &%s\n&, match(&ABB&,&a[a2b]b&)?&true&:&false& );
}复制代码
白手起家, 积分 5, 距离下一级还需 195 积分
论坛徽章:0
这个我倒没问,而且不是你说我还不知道有正则库这个东西,汗
小富即安, 积分 2464, 距离下一级还需 2536 积分
论坛徽章:0
justcoding
& & 这个东西, 如果用正则库确实不难. 如果不用正则库, 就相当于自己写正则库中的部分实现了.
& & 考虑到是一个题目的话, 实际上应该是看楼主知不知道正则库这回事了... 搜索C语言正则库即可...
& & 如果是要求正则全匹配而且不准用正则库的话, HoHo, 就相当于写一个正则库了, 这工作量... 不然呢, flex 什么的也是一个选择吧...
小富即安, 积分 2464, 距离下一级还需 2536 积分
论坛徽章:0
仔细看了下好像是只要求匹配中括号, 那不用正则库也是可以处理的... 不过确实还是有些麻烦, 粗略写来估计 bug 不少.
大富大贵, 积分 17274, 距离下一级还需 2726 积分
论坛徽章:84
fnmatch(3)
大富大贵, 积分 17274, 距离下一级还需 2726 积分
论坛徽章:84
* Copyright (c) , 1994
*& & & & The Regents of the University of California.&&All rights reserved.
* This code is derived from software contributed to Berkeley by
* Guido van Rossum.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
*& & notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
*& & notice, this list of conditions and the following disclaimer in the
*& & documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
*& & must display the following acknowledgement:
*& & & & This product includes software developed by the University of
*& & & & California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
*& & may be used to endorse or promote products derived from this software
*& & without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.&&IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* From FreeBSD fnmatch.c 1.11
* $Id: fnmatch.c,v 1.3
02:34:30 jdp Exp $
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = &@(#)fnmatch.c& & & & 8.2 (Berkeley) 4/16/94&;
#endif /* LIBC_SCCS and not lint */
* Function fnmatch() as specified in POSIX 2, section B.6.
* Compares a filename or pathname to a pattern.
#include &ctype.h&
#include &string.h&
#include &stdio.h&
#include &fnmatch.h&
#define& & & & EOS& & & & '\0'
static const char *rangematch(const char *, char, int);
int
fnmatch(const char *pattern, const char *string, int flags)
{
& & & & const char *
& & & & char c,
& & & & for (stringstart =;)
& & & & & & & & switch (c = *pattern++) {
& & & & & & & & case EOS:
& & & & & & & & & & & & if ((flags & FNM_LEADING_DIR) && *string == '/')
& & & & & & & & & & & & & & & & return (0);
& & & & & & & & & & & & return (*string == EOS ? 0 : FNM_NOMATCH);
& & & & & & & & case '?':
& & & & & & & & & & & & if (*string == EOS)
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & if (*string == '/' && (flags & FNM_PATHNAME))
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & if (*string == '.' && (flags & FNM_PERIOD) &&
& & & & & & & & & & & && &&&(string == stringstart ||
& & & & & & & & & & & && &&&((flags & FNM_PATHNAME) && *(string - 1) == '/')))
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & ++
& & & & & & & & & & & &
& & & & & & & & case '*':
& & & & & & & & & & & & c = *
& & & & & & & & & & & & /* Collapse multiple stars. */
& & & & & & & & & & & & while (c == '*')
& & & & & & & & & & & & & & & & c = *++
& & & & & & & & & & & & if (*string == '.' && (flags & FNM_PERIOD) &&
& & & & & & & & & & & && &&&(string == stringstart ||
& & & & & & & & & & & && &&&((flags & FNM_PATHNAME) && *(string - 1) == '/')))
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & /* Optimize for pattern with * at end or before /. */
& & & & & & & & & & & & if (c == EOS)
& & & & & & & & & & & & & & & & if (flags & FNM_PATHNAME)
& & & & & & & & & & & & & & & & & & & & return ((flags & FNM_LEADING_DIR) ||
& & & & & & & & & & & & & & & & & & & && &&&strchr(string, '/') == NULL ?
& & & & & & & & & & & & & & & & & & & && &&&0 : FNM_NOMATCH);
& & & & & & & & & & & & & & & & else
& & & & & & & & & & & & & & & & & & & & return (0);
& & & & & & & & & & & & else if (c == '/' && flags & FNM_PATHNAME) {
& & & & & & & & & & & & & & & & if ((string = strchr(string, '/')) == NULL)
& & & & & & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & & & & & /* General case, use recursion. */
& & & & & & & & & & & & while ((test = *string) != EOS) {
& & & & & & & & & & & & & & & & if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
& & & & & & & & & & & & & & & & & & & & return (0);
& & & & & & & & & & & & & & & & if (test == '/' && flags & FNM_PATHNAME)
& & & & & & & & & & & & & & & & & & & &
& & & & & & & & & & & & & & & & ++
& & & & & & & & & & & & }
& & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & case '[':
& & & & & & & & & & & & if (*string == EOS)
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & if (*string == '/' && flags & FNM_PATHNAME)
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & if ((pattern =
& & & & & & & & & & & && &&&rangematch(pattern, *string, flags)) == NULL)
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & ++
& & & & & & & & & & & &
& & & & & & & & case '\\':
& & & & & & & & & & & & if (!(flags & FNM_NOESCAPE)) {
& & & & & & & & & & & & & & & & if ((c = *pattern++) == EOS) {
& & & & & & & & & & & & & & & & & & & & c = '\\';
& & & & & & & & & & & & & & & & & & & & --
& & & & & & & & & & & & & & & & }
& & & & & & & & & & & & }
& & & & & & & & & & & & /* FALLTHROUGH */
& & & & & & & & default:
& & & & & & & & & & & & if (c == *string)
& & & & & & & & & & & & & & & & ;
& & & & & & & & & & & & else if ((flags & FNM_CASEFOLD) &&
& & & & & & & & & & & & & & & &&&(tolower((unsigned char)c) ==
& & & & & & & & & & & & & & & && &tolower((unsigned char)*string)))
& & & & & & & & & & & & & & & & ;
& & & & & & & & & & & & else if ((flags & FNM_PREFIX_DIRS) && *string == EOS &&
& & & & & & & & & & & && && &((c == '/' && string != stringstart) ||
& & & & & & & & & & & && && &(string == stringstart+1 && *stringstart == '/')))
& & & & & & & & & & & & & & & & return (0);
& & & & & & & & & & & & else
& & & & & & & & & & & & & & & & return (FNM_NOMATCH);
& & & & & & & & & & & & string++;
& & & & & & & & & & & &
& & & & & & & & }
& & & & /* NOTREACHED */
}
static const char *
rangematch(const char *pattern, char test, int flags)
{
& & & & int negate,
& & & & char c, c2;
& & & & /*
& & & &&&* A bracket expression starting with an unquoted circumflex
& & & &&&* character produces unspecified results (IEEE 2,
& & & &&&* 3.13.2).&&This implementation treats it like '!', for
& & & &&&* consistency with the regular expression syntax.
& & & &&&* J.T. Conklin (conklin@)
& & & &&&*/
& & & & if ( (negate = (*pattern == '!' || *pattern == '^')) )
& & & & & & & & ++
& & & & if (flags & FNM_CASEFOLD)
& & & & & & & & test = tolower((unsigned char)test);
& & & & for (ok = 0; (c = *pattern++) != ']';) {
& & & & & & & & if (c == '\\' && !(flags & FNM_NOESCAPE))
& & & & & & & & & & & & c = *pattern++;
& & & & & & & & if (c == EOS)
& & & & & & & & & & & & return (NULL);
& & & & & & & & if (flags & FNM_CASEFOLD)
& & & & & & & & & & & & c = tolower((unsigned char)c);
& & & & & & & & if (*pattern == '-'
& & & & & & & && &&&&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
& & & & & & & & & & & & pattern += 2;
& & & & & & & & & & & & if (c2 == '\\' && !(flags & FNM_NOESCAPE))
& & & & & & & & & & & & & & & & c2 = *pattern++;
& & & & & & & & & & & & if (c2 == EOS)
& & & & & & & & & & & & & & & & return (NULL);
& & & & & & & & & & & & if (flags & FNM_CASEFOLD)
& & & & & & & & & & & & & & & & c2 = tolower((unsigned char)c2);
& & & & & & & & & & & & if ((unsigned char)c &= (unsigned char)test &&
& & & & & & & & & & & && &&&(unsigned char)test &= (unsigned char)c2)
& & & & & & & & & & & & & & & & ok = 1;
& & & & & & & & } else if (c == test)
& & & & & & & & & & & & ok = 1;
& & & & }
& & & & return (ok == negate ? NULL : pattern);
}复制代码http://web.mit.edu/freebsd/csup/fnmatch.c

我要回帖

更多关于 c语言编程题目 的文章

 

随机推荐