當前位置:首頁 » 編程語言 » 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);應該就可以