C语言高手救命呀~~~

作者&投稿:濯沫 (若有异议请与网页底部的电邮联系)
C语言高手救命呀~~~~~

#include
#include
using namespace std;
int a[100]={0};
bool comp(int a,int b)
{
return a<b;
}
int main()
{
int n;
scanf("%d",&n);
int i;
for( i=0;i<n;i++ )
a[i]=rand()%100+1;
printf("排序前:
");
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("
");
sort(a,a+n,comp);
printf("排序后
");
for(i=0;i<n;i++)
printf("%d",a[i]);
printf("
");
int x;
printf("查找x(按F6结束):");
while(scanf("%d",&x)!=EOF)
{
int low=0;
int high=n-1;
int mid=(low+high)/2;
int flag=0;
if(a[low]==x)
{
mid=low;
flag=1;
}
else if(a[high]==x)
{
mid=high;
low=mid;
flag=1;
}
while(low!=mid&&flag==0)
{
if(a[mid]<x)
{
low=mid;
mid=(low+high)/2;
continue;
}
else if(a[mid]>x)
{
high=mid;
mid=(low+high)/2;
continue;
}
else
{
flag=1;
break;
}
}
if(flag)
printf("%d
",mid+1);
else
printf("-1
");
printf("查找x:");
}
return 0;
}

用凸包算法
#include
#include
#include
const double pi=acos(-1);
int used[1005];
double sum;
struct
{
int x, y;
}p[1005];
int n;
int cross(int xa,int ya,int xb,int yb)
{
return xa*yb-xb*ya;
}
double dis(int xa,int xb,int ya,int yb)
{
int dx,dy;
dx=xa-xb;
dy=ya-yb;
return sqrt(dx*dx+dy*dy);
}
int outbag(int cnt)
{
int i,flag=0,best,test;
for(i=0;i<n;i++)
{
if(used[i]==0&&i!=cnt)
{
if(flag==0)
{
best=i;
flag=1;
}
else
{
test=cross(p[best].x-p[cnt].x,p[best].y-p[cnt].y,p[i].x-p[cnt].x,p[i].y-p[cnt].y);
if(test<0)
best=i;
else if(test==0)
{
if(dis(p[best].x,p[cnt].x,p[best].y,p[cnt].y)<dis(p[i].x,p[cnt].x,p[i].y,p[cnt].y))
best=i;
}
}
}
}
if(flag==0)
return -1;
return best;
}
main()
{
int i,l,tx,ty,temp,re,s;
while(scanf("%d%d",&n,&l)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
tx=ty=1000000;
for(i=0;i<n;i++)
{
if(p[i].x<tx)
{
temp=i;
tx=p[i].x;
ty=p[i].y;
}
else if(p[i].x==tx&&p[i].y<ty)
{
temp=i;
ty=p[i].y;
}
}
//sum=l*2*pi;
sum=0;
s=temp;
memset(used,0,sizeof(used));
while(1)
{
re=outbag(temp);
sum+=dis(p[re].x,p[temp].x,p[re].y,p[temp].y);
if(re==s)
break;
used[re]=1;
temp=re;
}

printf("%.0f
",sum);
}
}

/****************************************************

实现单向链表(创建,打印,删除,添加)
lianbiao.c

****************************************************/
#include "stdio.h"
typedef struct LianBiao
{
int date;
struct LianBiao *next;
}LianBiao;

int sum; //全局变量num记录节点的个数
LianBiao* LineBiaoCreate()
{
struct LianBiao *p1 = NULL;
struct LianBiao *p2 = NULL;
struct LianBiao *head;
sum = 0;
p1 =(struct LianBiao *)malloc(sizeof(struct LianBiao));
if (p1 == NULL)
{
printf("error");
return NULL;
}
else
{
printf("please input lianbiao number:\n");
scanf("%d",&(p1->date));
}
p2 = p1;
while (p1->date != 0)
{
sum++;
if (sum == 1)
{
head = p1;
p2->next = NULL;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 =(struct LianBiao *)malloc(sizeof(struct LianBiao));
printf("please input lianbiao number:\n");
scanf("%d",&(p1->date));
}
p2->next = NULL;
free(p1);
p1 = NULL;
return head;
}

void PrintLineBiao(struct LianBiao *head)
{
struct LianBiao *p1;
struct LianBiao *p2;
p1 = head;
printf("链表数据:%d个\n",sum);
while (p1 != NULL)
{
printf("%d\n",p1->date);
p1 = p1->next;
}
}

struct LianBiao* DelLianBiao(struct LianBiao * head, int num)
{
struct LianBiao *p1;
struct LianBiao *p2;
if (head == NULL)
{
printf("this lianbiao is NULL");
return NULL;
}
p1 = head;
while(p1->date != num && p1->next != NULL)
{
p2 = p1;
p1 = p1->next;
}
if (num == p1->date)
{
if (p1 == head)
{
head = p1->next;
}
else
{
p2->next = p1->next;
}
sum = sum - 1;
}
else
{
printf("not find this number!");
}
return head;
}
InsertLianBiao(struct LianBiao* head, int num)
{
int i = 1;
struct LianBiao *p1,*p2;
p1 = head;
if (num > sum && num < 0)
{
printf("insert error!");
}
while (i < sum-1)
{
p1 = p1->next;
i++;
}
p2 = (struct LianBiao*)malloc(sizeof(struct LianBiao));
printf("please input Insert lianbiao number\n");
scanf("%d",&(p2->date));
p2->next = p1->next;
p1->next = p2;
sum++;
}
void main()
{
int i;
struct LianBiao * head;
head = LineBiaoCreate();
PrintLineBiao(head);
printf("输入要删除的数:\n");
scanf("%d",&i);
head=DelLianBiao(head,i);
PrintLineBiao(head);
printf("输入要插入的位置:\n");
scanf("%d",&i);
InsertLianBiao(head,i);
PrintLineBiao(head);
}


c语言高手救命啊
k-- 和 k=k-1 的执行效果是一样的,都是把 k 减少一个 但是 k-- 和 k=k-1 这两个表达式的值是不一样的 k-- 是先返回值,再减去1 比如现在k已经是0了,那么k--仍然返回0,while退出,这时候--才会生效,k变成-1 而k=k-1是先计算完,再返回 ...

C语言高手,救命啊!!!下面这段程序的运行结果是多少啊?
关键是最后这一句,我们看到的结果是从右边开始处理的。也就是说p在最后输出的时候虽然指向的是s[1],但是因为最后的那个p++操作使p指向了s[2],而++p操作又使p指向了s[3],所以输出的就是s[3]和s[1]这两个数了。

英语高手 救命啊~~~ 关于 语法的问题啦~~~ 请帮助我!!
主语:The 1870s 谓语:saw 宾语:the adoption 而that made railloads a leading source of technical innovation 是定语从句,修饰steel rails的; in the nineteenth century 是时间状语。The 1870s 做主语,名词结构,“十九世纪七十年代”的意思。The 1870s also saw 。。。属于“sth+see sth...

C语言高手快来救命。。。
这个排序很好写,用stdlib的qsort函数就行啦~用这个函数可以实现自定义的快排,可以排序的对象很多,基本上所有的数据结构能可以用它排的,结构体也很好排。具体用法网上有。我只给出我写的一个例子吧:define MAX_ITEMS 10typedef struct _Item Item;typedef struct _Data_info Data_info;typedef enum ...

C语言高手速来救命
include void Menu();void Plus();void Minus();void Multiply();void Dir();int main(){ int n, flag = 0;while(1){ Menu();do { flag = 0;scanf("%d", &n);switch(n){ case 1: Plus(); break;case 2: Minus(); break;case 3: Multiply(); break;case 4: Dir(...

求俄语高手。急,救命
1、首先是打招呼和自我介绍:Здравствуйте!Меня зовут...您好!我叫……(对方也自我介绍后)Очень приятно!很高兴认识您!2、接下来可以简单的寒暄,拉近与对方的距离,比如可以问问对方旅途是否顺利,休息得如何,是否第一次来中国等等。也可以表示对客人所在...

英语高手快来救命啊!!!急急急急急……
你是我的梦 you are my dream 在我眼里你最珍贵 you're beyond preasure in my eyes(其实意译的话,更好一点就是you are the apple in my eyes:你是我的掌上明珠)不要告诉我对或错 Do not tell me it's right or wrong 宝贝,相信我 babe(对女人的叫法~) just believe me 你在我眼里...

各位英语高手,救命
1.胜败乃兵家常事,何必介意?Victory and defeat are both common in battle,so why should care?2.活到老,学到老 It's never too old to learn.3.一千美元成交!Closed the deal for a thousand dollars

各路英语高手!!救命!!十万火急~~
1)11月12日风暴平息了 The storm of Nov. 12 has calmed down.2)他们突然大笑起来 They burst out laughing.3)这本字典是专门给小孩用的 The dictionary is especially for children.4)他在患重感冒 He has caught a bad cold.5)我们尽力消除他的疑虑,让他说出真相 We are trying our ...

高中英语高手来救命
这点我可以告诉你 真的 不是为了打击你 说实话 英语是一个厚积薄发的学科 因为它是一门语言 英语高考应该不算简单 我可以给你提几点建议 一 想要速成的 在最短的时间内 做完五三的英语 厚厚的那本 应该 40-50元 提高应该不小 二 保证一天一套模拟题 三 答题 按顺序答 完形大约用20分钟左右...

永康市13485465235: C语言高手速进...求救啊!
塔逄奥沙: k=sqrt(n); //只需要判断到根号n就行了 for(i=2;i<=k;i++) if(n%i==0) //对2到k的数判断能否整除n break; //当一有一个能整除n时就退出循环 if(i>=k+1) //判断之前的 i 是否已经加到了 k+1 ,如果是的话也就是之前所有的数都不能整除 n ,这就说明n是素数 return 1; else return 0; if(n%i==0) //对2到k的数判断能否整除n break; //当一有一个能整除n时就退出循环,如果没有循环到i = k+1 但是n%i==0了,这样退出在下面判断 i >= k+1 就是不成立,也就会是else ,将返回0,就说明不是素数了

永康市13485465235: 急求!各位C语言高手大哥救命!
塔逄奥沙: <script language="javascript"> for ( i = 1; i <= 10; i++ ) { alert("hello, world"); alert("somethings to tell you..."); } </script> 这样保存成html就最简单了~

永康市13485465235: 来C语言高手救救啊
塔逄奥沙: #include <stdio.h> void main(){ int a,b,c,max; printf("Please input a、b、c:\n"); scanf("%d%d%d",&a,&b,&c);//代码没啥问题,应该是你的输入加了,(逗号),而你在测试时没输入逗号导致的 max=a; if (max<b) max=b; if (max<c) max=c; printf("The largest number is %d\n",max);}

永康市13485465235: C程序高手,救命啊
塔逄奥沙: #include<stdio.h> int a,b,c,v; scanf("%d%d%d",&a,&b,&c); v=a*b*c; printf("V=%d",v);

永康市13485465235: 救命啊!求C语言高手,好像关于字符串的
塔逄奥沙: 回答这个不需要高手.不知道用什么函数? 好办,c/c++库函数(中文).chm,这个工具可以帮助你找到自己想要的库函数. 例如:memcpy函数可以把字符串复制到数组里.

永康市13485465235: 救命啊!C语言高手们,指针的问题真是一窍不通啊
塔逄奥沙: &就是取地址,*就是取地址上的值 1.定义了一个指针变量*ptr,ptr=&b;是把b的地址取出来赋给ptr,这是ptr指向变量b,即*ptr就是b. 2.*ptr=&b定义一个指针变量ptr并且指向b,a=*ptr就是把b的值赋值给a,等同于a=b. 3.同理,*ptr就是变量c,下面的代码就是把c的值赋值给b,然后把a的值赋值给c. 4.同理定义指针变量*ptr,把c的地址赋值给ptr使*ptr指向变量c,b赋值给c,此时a=*ptr就是a=c.

永康市13485465235: 会C语言的高手来救命啊~~
塔逄奥沙: Borlandc C++ 3.1编译器哦.

永康市13485465235: c语言问题 高手速回救命!!!
塔逄奥沙: 试试这些代码 #include <stdio.h> void main() { int a[9]={1,2,3,4,5,6,7,8,9}; for(int i=0;i<9;i++) { printf("%d",a[i]); } } 哦,漏了个0, #include <stdio.h> void main() { int a[9]={0,1,2,3,4,5,6,7,8,9}; for(int i=0;i<=9;i++) { printf("%d",a[i]); } }

永康市13485465235: c程序高手!救命啊 -
塔逄奥沙: #include<stdio.h> void main() { /*void move(array,n,m);应该是*/ void move(int *array,int n,int m); int number[20],n,m,i; printf("共有多少个数?"); scanf("%d",&n); printf("共移多少位数?"); scanf("%d",&m); printf("请以逗号为...

永康市13485465235: 高手救命!C语言回文数,我用最简单的方法编了,但答案不理想! -
塔逄奥沙: 给出以下代码,你看看和你的算法有什么不同. 我的算法是: 1、读入这个数,用一个字符串保存; 2、用另一个字符串存储这个数的逆序数; 3、比较两个字符串,看是否相同. #include#include#includevoid check (int i) { char p[6],q[6]; int length; register int j,r; _itoa (i, p, 10); //数字到字符的转化 length = strlen(p); //获得p的长度 r = length; // q[r] = '\0'; // r--; // for (j= 0 ; j

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网