当前位置:首页 » 编程语言 » c语言strip
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言strip

发布时间: 2022-05-12 14:08:45

⑴ 请高手用c语言写一段判断是否是回文的程序

栈实现的
#include<stdio.h>
#include<stdlib.h>
#define MAXCHAR 40

struct node
{
char data;
struct node *next;
};
int ishs(struct node *head,int n)
{
char stack[MAXCHAR/2];
struct node *p = head;
int top = 0;

while(top<n/2) //前半部分元素入栈
{
stack[top] = p->data;
top++;
p = p->next;
}
if(n%2==1) //n为奇数
p = p->next;
top--;

while(top>=0 && p!=NULL && stack[top]==p->data) //边退栈边比较
{
top--;
p = p->next;
}
if(top==-1 && p==NULL) //栈空且链表比较完毕,是回文数
return 1;
else return 0;
}
void main(void)
{
char s[MAXCHAR];
struct node *head = NULL,*p,*q;
int i=0;

printf("输入一个数:");
scanf("%s",s);

while(s[i]!='\0') //建立字符串单链表
{
p = (struct node*)malloc(sizeof(struct node));
p->data = s[i];
p->next = NULL;
if(head==NULL)
{
head = p;
q = p; //q总指向最后一个结点
}
else
{
q->next = p;
q = p;
}
i++;
}
if(ishs(head,i))
printf("%s是回文数\n",s);
else
printf("%s不是回文数\n",s);
}

⑵ c语言如何编程

C语言编程如何快速实现

在我们初次学习C语言的时候,总想着快速的实现编译过程。那么C语言编程究竟是如何实现的呢,当然是要通过自己喜欢的编译器来编译完成,那么今天就为大家介绍C语言编程是如何快速的实现。

1. 首先我们下载一款适合C语言的编译器,今天为大家讲解的C语言编译器为CodeBlocks,该编译器没有太过复杂,很符合初学者,简单上手快。

⑶ c语言链表问题

#include<iostream.h>
main()
{
//声明变量
inti,j;
floatt,a[5];

//从键盘上为数组赋值
for(i=0;i<=4;i++)
{
cout<<"a["<<i<<"]=";
cin>>a[i];
}

//对数组按从大到小顺序排序
for(i=0;i<=3;i++)
for(j=i+1;j<=4;j++)
if(a[i]<=a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}

//显示排序结果
for(i=0;i<=4;i++)
cout<<a[i]<<"";
}
#include<iostream.h>
main()
{
//声明二维数组及变量
inta[2][3],i,j;

//从键盘上为数组a赋值
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
}

//显示数组a
for(i=0;i<2;i++){
for(j=0;j<3;j++)
{
cout<<a[i][j]<<"";
}
cout<<endl;
}

//找出该数组的最大元素及其下标
inth,l,Max=a[0][0];
for(i=0;i<2;i++){
for(j=0;j<3;j++)
{
if(Max<a[i][j]){
Max=a[i][j];
h=i;
l=j;
}
}
}
cout<<"Max:"<<"a["<<h<<"]["<<l<<"]="<<a[h][l]<<endl;
}
#include<iostream.h>
main()
{
//声明字符数组和变量
charstr[6];
inti;

//从键盘上输入字符串
cout<<"str=";
cin>>str;
cout<<str<<endl;

//按数组和下标变量两种方式显示字符数组
cout<<str<<endl;
for(i=0;i<6;i++)
cout<<str[i];
cout<<endl;

//字符串反向输出
for(i=5;i>=0;i--)
cout<<str[i];
cout<<endl;

//将字符数组变成大写字母后输出
for(i=0;i<=5;i++)
str[i]-=32;//小写字母转换成大写字母
cout<<str<<endl;//显示字符串
}
#include<iostream.h>
main()
{
//声明变量和指针变量
inta,b,c,*ip;

//指针变量ip指向变量a
a=100;
ip=&a;//使指针变量ip指向变量a
cout<<"a="<<a<<endl;
cout<<"*ip="<<*ip<<endl;
cout<<"ip="<<ip<<endl;

//指针变量ip指向变量b
ip=&b;//使指针变量ip指向变量b
b=200;
cout<<"b="<<b<<endl;
cout<<"*ip="<<*ip<<endl;
cout<<"ip="<<ip<<endl;

//指针变量ip指向变量c
ip=&c;//使指针变量ip指向变量b
*ip=a+b;
cout<<"c="<<c<<endl;
cout<<"*ip="<<*ip<<endl;
cout<<"ip="<<ip<<endl;
}
#include<iostream.h>
main()
{
//声明数组、变量和指针变量
inta[2][3],i,j;
int*ip;

//从键盘上为数组a赋值
for(i=0;i<2;i++)//为数组a赋值
for(j=0;j<3;j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
}

//利用下标变量显示数组a
for(i=0;i<2;i++){
for(j=0;j<3;j++)
{
cout<<a[i][j]<<"";
}
cout<<endl;
}

//利用指针变量显示数组a
ip=&a[0][0];
for(i=0;i<2;i++){
for(j=0;j<3;j++)
{
cout<<"a["<<i<<"]["<<j<<"]=";
cout<<ip<<"";
cout<<*ip<<endl;
ip++;
}
}
}
#include<iostream.h>
main()
{
//声明数组、变量和指针变量
inta[]={1,2,3,4,5,6};
int*ip1,*ip2;

//测试指针的赋值运算
ip1=a;
ip2=ip1;
cout<<"*ip1="<<(*ip1)<<endl;
cout<<"*ip2="<<(*ip2)<<endl;

//测试指针的自增自减运算和组合运算
ip1++;
ip2+=4;
cout<<"*ip1="<<(*ip1)<<endl;
cout<<"*ip2="<<(*ip2)<<endl;

//测试指针变量之间的关系运算
intn=ip2>ip1;
cout<<"ip2>ip1="<<n<<endl;
cout<<"ip2!=NULL="<<(ip2!=NULL)<<endl;

//指针变量之间的减法
n=ip2-ip1;
cout<<"ip2-ip1="<<n<<endl;
}
#include<iostream.h>
main()
{
//声明字符型数组和指针变量
charstr[10];
char*strip=str;

//输入输出
cout<<"str=";
cin>>str;//用字符数组输入字符串
cout<<"str="<<str<<endl;
cout<<"strip="<<strip<<endl;
cout<<"strip=";
cin>>strip;//用字符指针变量输入字符串
cout<<"str="<<str<<endl;
cout<<"strip="<<strip<<endl;

//利用指针变量改变其指向字符串的内容
*(strip+2)='l';
cout<<"str="<<str<<endl;
cout<<"strip="<<strip<<endl;

//动态为字符型指针变量分配内存
strip=newchar(100);
cout<<"strip=";
cin>>strip;//用字符指针变量输入字符串
cout<<"str="<<str<<endl;
cout<<"strip="<<strip<<endl;
}

⑷ c语言编写程序

学习c语言一定要自己多上机练习,这个题是基础题。
主要涉及到如何定义一个变量,简单运算符号的使用,以及输出函数的使用:
定义一个变量用法: 类型 变量名称,如int a; float a; c语言每条语句以分号结束;
数学符号跟我们平常是一样的;
printf(格式,参数列表)函数输出,格式为字符串,里面的多少%d参数列表要对应几个整型变量。%c 对应字符变量,%s字符串变量,%lf对应double变量。
代码如下:
#include<stdio.h>
int main()
{
int a;
int b;
int c;
a = 6;
b = 7;
c = 2*a+b;
printf("c = %d\n", c);
return 0;
}

⑸ c语言怎么编写

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

char fun(char *a,char *b)

{

char *t;

strcpy(t,a);

strcpy(a,b);

strcpy(b,t);

}

struct st{

char a[6][20];

};

int main()

{

struct st s[111];

int n,x[111],k=0,ts,sum=0;

scanf("%d",&n);

printf("学号 姓名 数学 物理 英语 计算机 ");

for(int i=0;i<n;i++)

{

sum=0;

for(int j=0;j<6;j++)

{

scanf("%s",s[i].a[j]);

if(j!=0&&j!=1)

{

sum+=atoi(s[i].a[j]);

}

}

x[k++]=sum/3;

}

for(int i=0;i<k;i++)

{

for(int j=0;j<k-i-1;j++)

{

if(x[j]>x[j+1])

{

ts=x[j];

x[j]=x[j+1];

x[j+1]=ts;

for(int l=0;l<6;l++)

fun(s[j].a[l],s[j+1].a[l]);

}

}

}

printf("学号 姓名 数学 物理 英语 计算机 平均成绩 ");

for(int i=0;i<n;i++)

{

for(int j=0;j<6;j++)

{

printf("%s",s[i].a[j]);

for(int k=0;k<8-strlen(s[i].a[j]);k++)

printf(" ");

}

printf("%8d ",x[i]);

}

return 0;

}

⑹ python中的字符串操作,与c语言中的字符串操作有何异同

s.strip() .lstrip() .rstrip(',') 去空格及特殊符号

复制字符串
Python
1 #strcpy(sStr1,sStr2)
2 sStr1 = 'strcpy'
3 sStr2 = sStr1
4 sStr1 = 'strcpy2'
5 print sStr2
连接字符串
Python
1 #strcat(sStr1,sStr2)
2 sStr1 = 'strcat'
3 sStr2 = 'append'
4 sStr1 += sStr2
5 print sStr1
查找字符
< 0 未找到
Python
1 #strchr(sStr1,sStr2)
2 sStr1 = 'strchr'
3 sStr2 = 's'
4 nPos = sStr1.index(sStr2)
5 print nPos
比较字符串
Python
1 #strcmp(sStr1,sStr2)
2 sStr1 = 'strchr'
3 sStr2 = 'strch'
4 print cmp(sStr1,sStr2)
扫描字符串是否包含指定的字符
Python
1 #strspn(sStr1,sStr2)
2 sStr1 = '12345678'
3 sStr2 = '456'
4 #sStr1 and chars both in sStr1 and sStr2
5 print len(sStr1 and sStr2)
字符串长度
Python
1 #strlen(sStr1)
2 sStr1 = 'strlen'
3 print len(sStr1)
将字符串中的大小写转换
Python
1 #strlwr(sStr1)
2 sStr1 = 'JCstrlwr'
3 sStr1 = sStr1.upper()
4 #sStr1 = sStr1.lower()
5 print sStr1
追加指定长度的字符串
Python
1 #strncat(sStr1,sStr2,n)
2 sStr1 = '12345'
3 sStr2 = 'abcdef'
4 n = 3
5 sStr1 += sStr2[0:n]
6 print sStr1
字符串指定长度比较
Python
1 #strncmp(sStr1,sStr2,n)
2 sStr1 = '12345'
3 sStr2 = '123bc'
4 n = 3
5 print cmp(sStr1[0:n],sStr2[0:n])
复制指定长度的字符
Python
1 #strncpy(sStr1,sStr2,n)
2 sStr1 = ''
3 sStr2 = '12345'
4 n = 3
5 sStr1 = sStr2[0:n]
6 print sStr1
将字符串前n个字符替换为指定的字符
Python
1 #strnset(sStr1,ch,n)
2 sStr1 = '12345'
3 ch = 'r'
4 n = 3
5 sStr1 = n * ch + sStr1[3:]
6 print sStr1
扫描字符串
Python
1 #strpbrk(sStr1,sStr2)
2 sStr1 = 'cekjgdklab'
3 sStr2 = 'gka'
4 nPos = -1
5 for c in sStr1:
6 if c in sStr2:
7 nPos = sStr1.index(c)
8 break
9 print nPos
翻转字符串
Python
1 #strrev(sStr1)
2 sStr1 = 'abcdefg'
3 sStr1 = sStr1[::-1]
4 print sStr1
查找字符串
Python
1 #strstr(sStr1,sStr2)
2 sStr1 = 'abcdefg'
3 sStr2 = 'cde'
4 print sStr1.find(sStr2)
分割字符串
Python
1 #strtok(sStr1,sStr2)
2 sStr1 = 'ab,cde,fgh,ijk'
3 sStr2 = ','
4 sStr1 = sStr1[sStr1.find(sStr2) + 1:]
5 print sStr1
6 或者
7 s = 'ab,cde,fgh,ijk'
8 print(s.split(','))
连接字符串
Python
1 delimiter = ','
2 mylist = ['Brazil', 'Russia', 'India', 'China']
3 print delimiter.join(mylist)
PHP 中 addslashes 的实现
Python
1 def addslashes(s):
2 d = {'"':'\\"', "'":"\\'", "\0":"\\\0", "\\":"\\\\"}
3 return ''.join(d.get(c, c) for c in s)
4
5 s = "John 'Johny' Doe (a.k.a. \"Super Joe\")\\\0"
6 print s
7 print addslashes(s)
只显示字母与数字
Python
1 def OnlyCharNum(s,oth=''):
2 s2 = s.lower();
3 fomart = ''
4 for c in s2:
5 if not c in fomart:
6 s = s.replace(c,'');
7 return s;
8
9 print(OnlyStr("a000 aa-b"))

⑺ 如何写个C程序来判断ELF二进制文件是否被strip了

你编译好的可执行文件就是二进制文件,包括机器码指令和数据。Linux上生成的一般是ELF格式,带文件头和段记录,你可以用strip什么的去掉。

⑻ C语言编写的程序编译成功但运行失败

printf("%s",*name);//很明显是这个错了,为什么要加*号
//改为printf("%s",name);应该就可以