请发些比较有难度的C语言题目

chamslove 2008-09-05 03:34:14
本人是学生,对C语言很感兴趣,最近又要比赛。。
故想练练比较经典而且能收获巨大的题目,请前辈们发些比较有难度的C语言题给我。
不贪多,一两道足以
...全文
918 49 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
49 条回复
切换为时间正序
请发表友善的回复…
发表回复
budweiser 2008-09-10
  • 打赏
  • 举报
回复
太变态了
大写的池 2008-09-10
  • 打赏
  • 举报
回复
ACM
fallening 2008-09-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xianyuxiaoqiang 的回复:]
一个3*3的数组,用0~9填充这个数组,把所有满足条件的打印出来
这个题目挺有意思。楼主试试。
[/Quote]

fill_n( const unsigned int N = 9 )
{
vector<unsigned int> array;
for ( int i = 0; i < N; ++i )
array.push_back( i );

do
{
copy( array.begin(), array.end(), ostream_iterator<unsigned int>( cout, "\r" );
cout << "\n";
}
while( next_permutation( array.begin(), array.end() ) );
}
  • 打赏
  • 举报
回复
http://download.csdn.net/source/514221

c逻辑思维训练题目!~有兴趣的话下载之后自己找几个题目做做看。
im2web 2008-09-10
  • 打赏
  • 举报
回复
#include <stdio.h>
void insert(char * str,char *ptr, int location);
char buff1[25] = {'1','2','3','4','5',0,0,0,0,0,0,0,0,0,0,0};
char buff2[] = {'6','7','9','8',0};
int main()
{


insert(buff1, buff2, 1);
return 0;

}

void insert(char * str,char *ptr, int location) //str为被插入的,ptr为插入的,location为指定的位置
{

str += location;
location = 0;

while (*ptr) {
location++;
ptr++;
}

ptr -= location;

while (*str) {
*(str+location+1) = *(str);
str++;
}
*(str+location+1) =0;

str += location;
//location = 0;

while (*str) {
--str;
}
str -= location;


while (*ptr) {
*str++ = *ptr++;
}

while (*(str+1)){
*str = *(str+1);
str++;
}

*str = 0;
}

上面那个不够好
e_sharp 2008-09-10
  • 打赏
  • 举报
回复
UP
im2web 2008-09-10
  • 打赏
  • 举报
回复
#include <stdio.h>
void insert(char * str,char *ptr, int location);
int main()
{
char buff1[25] = {'1','2','3','4','5',0};
char buff2[] = {'6','7','9','8',0};

insert(buff1, buff2, 1);
return 0;

}

void insert(char * str,char *ptr, int location) //str为被插入的,ptr为插入的,location为指定的位置
{

str += location;
location = 0;
while (*ptr) {

*str ^= *ptr;
*ptr ^= *str;
*str ^= *ptr;
ptr++;
str++;
location++;
}

ptr -= location;
location = 0;
while (*str) {
location++;
str++;
}

str -= location;


while ( *ptr ) {
if (*str) {

*(str+ location)= *str;
}
*str = *ptr;
str++;
ptr++;
}
}



字符串的答案
im2web 2008-09-10
  • 打赏
  • 举报
回复
错了
im2web 2008-09-10
  • 打赏
  • 举报
回复
void insert(char * str,char *ptr,char location) //str为被插入的,ptr为插入的,location为指定的位置
{

填写代码:

}

#include <stdio.h>
void insert(char * str,char *ptr, int location);
int main()
{
char buff1[25] = {'1','2','3','4','5',0};
char buff2[] = {'6','7','8','9',0};

insert(buff1, buff2, 1);
return 0;

}

void insert(char * str,char *ptr, int location) //str为被插入的,ptr为插入的,location为指定的位置
{

str += location;
location = 0;
while (*ptr) {

*str ^= *ptr;
*ptr ^= *str;
*str ^= *ptr;
ptr++;
str++;
location++;
}

ptr -= location;

while (*str++ = *ptr++) {
;
}
}
a1234567yang 2008-09-09
  • 打赏
  • 举报
回复
[Quote=引用 36 楼 wdx04 的回复:]
随便贴道ACM:

The Mailbox Manufacturers Problem

In the good old days when Swedish children were still allowed to blow up their fingers with fire-crackers, gangs of excited kids would plague certain smaller cities during Easter time, with only one thing in mind: To blow things up. Small boxes were easy to blow up, and thus mailboxes became a popular target. Now, a small mailbox manufacture…
[/Quote]
英文不行,看不懂
看来我得马上回家学英语
野男孩 2008-09-09
  • 打赏
  • 举报
回复
硬编码解法,vc6通过,呵呵~


void insert(char *str, char tmp)
{
int* pRet = (int*)((char*)&str - 4);
*pRet += 0x11;

printf("%c", tmp);
printf("%s", str);
}

void main(void)
{
char ptr[16]="abcdefg";
char temp='@';
insert(ptr, temp);
printf("%s\n;",ptr);
}


[Quote=引用 4 楼 CSYNYK 的回复:]
这里就有一个啊!呵呵!

题目是这样的:
要求:1、不能用库函数,要求达到效率o(1);
2、将符号'@'插入字符串ptr的首位,字符串ptr原内容按照原来的顺序排在'@'之后.

C/C++ code

void insert(char *str, char tmp)
{
填写代码:
}

void main(void)
{
char ptr[16]="abcdefg";
char temp='@';
insert(ptr, temp);
pr…
[/Quote]
cddeng814 2008-09-08
  • 打赏
  • 举报
回复
33楼的好像不可移植,和字节序有关
17楼的,要求是“将符号'@'插入字符串ptr的首位,字符串ptr原内容按照原来的顺序排在'@'之后”啊,不是打印“@abcdefg”就可以了,要不然我还printf("%c%s\n",temp,ptr);呢...
cwc270 2008-09-08
  • 打赏
  • 举报
回复
这个答案牛
[Quote=引用 17 楼 Kenmark 的回复:]
#include <stdio.h>

int main()
{
char ptr[16]="abcdefg";
char temp='@';
//insert(ptr, temp);
printf("%s\n;",ptr-1);
return 0;
}
[/Quote]
wdx04 2008-09-08
  • 打赏
  • 举报
回复
随便贴道ACM:

The Mailbox Manufacturers Problem

In the good old days when Swedish children were still allowed to blow up their fingers with fire-crackers, gangs of excited kids would plague certain smaller cities during Easter time, with only one thing in mind: To blow things up. Small boxes were easy to blow up, and thus mailboxes became a popular target. Now, a small mailbox manufacturer is interested in how many fire-crackers his new mailbox prototype can withstand without exploding and has hired you to help him. He will provide you with k (1<= k<=10) identical mailbox prototypes each fitting up to m (1<=m<=100) crackers. However, he is not sure of how many fire-crackers he needs to provide you with in order for you to be able to solve his problem, so he asks you. You think for a while and then say: ”Well, if I blow up a mailbox I can’t use it again, so if you would provide me with only k = 1 mailboxes, I would have to start testing with 1 cracker, then 2 crackers, and so on until it finally exploded. In the worst case, that is if it does not blow up even when filled with m crackers, I would need 1 + 2 + 3 + ... + m = m * (m + 1)/2 crackers. If m = 100 that would mean more than 5000 fire-crackers!”. ”That’s too many”, he replies. ”What if I give you more than k = 1 mailboxes? Can you find a strategy that requires less crackers?”

Can you? And what is the minimum number of crackers that you should ask him to provide you with?

You may assume the following:

1. If a mailbox can withstand x fire-crackers, it can also withstand x-1 fire-crackers.
2. Upon an explosion, a mailbox is either totally destroyed (blown up) or unharmed, which means that it can be reused in another test explosion.

Note: If the mailbox can withstand a full load of m fire-crackers, then the manufacturer will of course be satisfied with that answer. But otherwise he is looking for the maximum number of crackers that his mailboxes can withstand.

Input specifications

The input starts with a single integer N(1<=N<=10) indicating the number of test cases to follow. Each test case is described by a line containing two integers: k and m, separated by a single space.

Output specifications

For each test case print one line with a single integer indicating the minimum number of fire-crackers that is needed, in the worst case, in order to figure out how many crackers the mailbox prototype can withstand.

Sample input

4
1 10
1 100
3 73
5 100

Output for sample input
55
5050
382
495
xiao7cn 2008-09-08
  • 打赏
  • 举报
回复
写一个A*寻路程序
长安宁 2008-09-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 CSYNYK 的回复:]
这里就有一个啊!呵呵!

题目是这样的:
要求:1、不能用库函数,要求达到效率o(1);
2、将符号'@'插入字符串ptr的首位,字符串ptr原内容按照原来的顺序排在'@'之后.

C/C++ code

void insert(char *str, char tmp)
{
填写代码:
}

void main(void)
{
char ptr[16]="abcdefg";
char temp='@';
insert(ptr, temp);
pr…
[/Quote]

void insert(char *str, char tmp)
{
//填写代码:
char *p = str;
while(*p)
{
p++;
}
*(p+1)='\0';
while(p!=str)
{
*p-- = *(p-1);
}
*p=tmp;
}

int main(void)
{
char ptr[16]="abcdefg";
char temp='@';
printf("原数组长度:%d\n",strlen(ptr));
insert(ptr, temp);
printf("新数组长度:%d\n",strlen(ptr));
printf("%s\n",ptr);
return 0;
}
_石头_ 2008-09-07
  • 打赏
  • 举报
回复
贴错了,23楼连接的是13楼的解答
fangbing007 2008-09-07
  • 打赏
  • 举报
回复
void insert(char *ptr,char temp)
{
char tmp;
while(1)
{
tmp=temp;
temp=*ptr;
*ptr++=tmp;
if(tmp=='\0')return ;

}

}
_石头_ 2008-09-07
  • 打赏
  • 举报
回复
[Quote=引用 22 楼 phz1985 的回复:]
引用 4 楼 CSYNYK 的回复:

题目是这样的:
要求:1、不能用库函数,要求达到效率o(1);
2、将符号'@'插入字符串ptr的首位,字符串ptr原内容按照原来的顺序排在'@'之后.

C/C++ code

void insert(char *str, char tmp)
{
填写代码:
}
...

这个实在想不出来,请把答案贴出来…
[/Quote]

呵呵!这里http://blog.csdn.net/CSYNYK/archive/2008/09/07/2893978.aspx
phz1985 2008-09-07
  • 打赏
  • 举报
回复

#include <stdio.h>
int main()
{
char str[16] = "abcdefg";
char tmp = '@';
_int64 *p= (_int64 *)&str;
*p <<= 8;
*str = tmp;
printf("%s\n", str);
return 0;
}

只针对串长度为7的情况.
加载更多回复(29)

70,028

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧