1樓:珈藍惜夢
源程式**以及演算法解釋如下:
#define _crt_secure_no_warnings//vs環境下需要,vc不需要
#include
#include
int main()
;//字元陣列
int numb_count = 0;//數字個數
int abc_count = 0;//大寫字母個數
int abc_count = 0;//小寫字母個數
scanf("%s", str);//連續輸入字元到字元陣列
while (str[i] != '\0')
else if ((str[i] >= 'a') && (str[i] <= 'z'))//判斷是否是小寫字母
else if ((str[i] >= 'a') && (str[i] <= 'z'))//判斷是否是大寫字母
i++;
}printf("數字個數:%d\n小寫字母個數:%d\n大寫字母個數:%d\n", numb_count, abc_count, abc_count);
return 0;
程式執行結果如下:
擴充套件資料:
其他實現方式:
#include "stdafx.h"
#include
int main()
char str[80]="\0",resultstr[80]="\0";
int cursor=0;
printf("請輸入字串:");
scanf("%s",str);
char *tempstr = str;
while (*tempstr != '\0')
char ch = *tempstr;
if ((ch>='a'&&ch<='z')||(ch>='a'&&ch<='z'))
resultstr[cursor] = ch;
cursor++;
tempstr++;
printf("輸入字元為:%s\n輸出字元為:%s\n",str,resultstr);
system("pause");
return 0;
2樓:德銀河
2個程式我都寫了
#include
#include
int main()
printf("大寫字母個數:%d\n",abc);
printf("小寫字母個數:%d\n",abc);
printf("數字個數:%d\n",num);
return 0;}
3樓:匿名使用者
第2題#include
using namespace std;
int main(void)
//end if
}while(i < szstr);
cout << -1<
using namespace std;
int main(void)
// 注意這裡把跳格也當成空格計算
if (c >= '0' && c <= '9')if (c >= 'a' && c <= 'z')if (c >= 'a' && c <= 'z')other ++;
}cout<<"數字"< return 0;} 4樓:匿名使用者 #include #include int find(char str, char c)void cout(char str) void main() 編寫程式,統計輸入的字串中大寫英文字母,小寫英文字母,數字和其它字元的個數.(用陣列 c++ ) 5樓:匿名使用者 #include using namespace std; int main(void) cout<<"數字個數為:"< cout<<"大寫字母個數為:"< cout<<"小寫字母個數為:"< cout<<"其他字元個數為:"< 求c++大神,如果輸入一行字串,只有空格隔開,怎樣將它們分配到多個陣列中? 6樓: 這好辦啊—— #include int main(void){ char s[220],s2[30][20]; int i,j,t; printf("input a string...\n"); gets(s); for(j=0;j 用c++編寫:輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數? 7樓:妖刀路過 #include #include void main() else if(0<=*str<=9) else if(*str==' ') else }printf("%d%d%d%d",letter,blank,num,other);} c++ 輸入一行字串,內有數字和非數字字元,將其中連續的數字作為一個整數,依此存放到一陣列a中 8樓:匿名使用者 #include using namespace std; int main() ,sum=0,i,j=0; char str[200]=; cin.getline(str,200); for(i=0;i<=200;i++) }for(i=0;i 9樓: int chompnum(char* str, char** to)else if (dig) str++; }if (dig) return num; }int main() return 0;} 10樓:匿名使用者 是數字就存入其他不存入嗎? c++中如何將輸入的字串(不知長度)存入陣列中? 11樓:楊武威 #include #include #include using namespace std; int main() const int len =str.length(); char* dest = new char[len];//根據輸入字串的長度,建立字元陣列 for(int i = 0;i delete dest; system("pause"); return 0;} c++中如何將輸入的字串(不知長度)存入陣列中?最好用**回答. 12樓:楊武威 #include #include #include using namespace std; int main() const int len =str.length(); char* dest = new char[len];//根據輸入字串的長度,建立字元陣列 for(int i = 0;i delete dest; system("pause"); return 0;} 13樓:光腳滿地跑 如果可以使用string類的話那很方便了 先用string類接受輸入 再轉換為char* 對於「不知長度」的輸入,如果我的輸入超出了記憶體的限制,不也是會fail的麼,所以一定有某種「限制」輸入的長度。 14樓:匿名使用者 char s[255]; cin.getline(s,255) 後邊可以用 strlen(s) 獲取到實際長度 15樓:上語文課註冊的 #包括#包括中 無效的主要() 的printf(「排序後:\ n」); (i = 0; <4 + +) 看跌期權();} 16樓:匿名使用者 #includevoid main() c++程式設計題 輸入一個字串,存入陣列a,將其複製到陣列b,然後將陣列b中所有小寫字母改為大寫字母
5 17樓:似等及 如果是陣列, 在a,b設定一個i和j, 指向當前元素, 初始指向第一個元素. 如果i和j所指都有元素,比較i,j所指元素大小, 把大的複製到c, 並且相應的i或j+1.(誰大加誰), c也+1右移一位,如果i或j沒有元素,那麼就忽略沒有元素的那個表, 直接複製剩下下的到c . 迴圈的停止條件是i和j都沒有元素了. 如果是連結串列, 那麼就修改相應的next域, 原理同上.不用建立或者刪除新節點, 而是將結點順序重新規劃, 注意next域的修改順序防止掉鏈, 你自己畫個圖研究一下即可. 最後達到的效果是a, b連結串列都消失, 形成一個c連結串列以降序排列 18樓:篤俠 #include using namespace std; void converse(char *x)void connect(char *d, char *s)int compare(char *s, char *t) c++編寫程式,輸入一個字串(少於80個字元),在原字元陣列中刪除所有的非英文字母后,組成新的字串輸出 19樓:匿名使用者 #include "stdafx.h" #include int main() char str[80]="\0",resultstr[80]="\0"; int cursor=0; printf("請輸入字串:"); scanf("%s",str); char *tempstr = str; while (*tempstr != '\0')char ch = *tempstr; if ((ch>='a'&&ch<='z')||(ch>='a'&&ch<='z')) resultstr[cursor] = ch; cursor++; tempstr++; printf("輸入字元為:%s\n輸出字元為:%s\n",str,resultstr); system("pause"); return 0; 20樓:孤鬆獨海 那就迴圈判斷 利用 isalpha 或者 判斷在不在az 和az之間 可以再定義一個字元陣列 將符合情況的存到新陣列裡面 21樓:庹靈波 把你的書翻到附錄部分,有個ascii碼錶,對吧,根據16進位制判斷就可以了 22樓:匿名使用者 int i, j = 0; char *input[81]; char *output[81]; cout << "input a string: "; cin >> input; for (i=0; i 問明 要統計英文字母,空格,數字和其他字元的個數,如下 include include int main char c int letters 0 int space 0 int digit 0 int other 0 printf 請輸入一行字元 while c getchar n if c a ... 泡影果果 從檔案中讀取資料,一行一行的讀取,用getline include fstream in cstring strfilename e 測試 a.txt 路徑是雙斜槓 in.open strfilename,ios in ios base in while in.eof 如果沒有讀到檔案結尾... 使用動態分配來解決。問記憶體要空間,自己管理。即動態分配 例 不完整 define buffer 512 問記憶體申請空間存放字元個數char p p char malloc buffer sizeof char 申請 管理使用 free p 釋放 由於計算機記憶體有限,所以理論上不可能輸入任意長度...c語言輸入一行字串,如何統計其中的字母和數字的個數
運用C 如何讀取一行字串的指定字元
C語言程式設計 如何輸入任意長度的字串?(不用C 和String)