說明
連續輸入N個字串(-1結束不含-1),將字串中小寫英文字母轉成大寫後依輸入順序印出
Input Format
字串1(可含空白)
字串...(可含空白)
字串N(可含空白)
-1
Output Format
轉大寫後的字串1(換行)
轉大寫後的字串...(換行)
轉大寫後的字串N(換行)
你需要更多的練習,不是答案。
僅供參考:
#include <stdio.h>
#include <queue>
int main() {
std::queue<int> letters;
unsigned char alp;
while(true) {
alp = getchar();
getchar();
if(alp == '-')
break;
letters.push(alp);
}
while(!letters.empty()) {
printf("%c\n", letters.front() - 32);
letters.pop();
}
}
#include"stdio.h"
#include"ctype.h"
#include"string.h"
int main(){
char Name[4][20];
int i,j,Len,Codeinteger;
for(i=0;i<4;i++){
gets(Name[i]);
Codeinteger = atoi(Name[i]);
if(Codeinteger == -1){
break;
}
Len = strlen(Name[i]);
for(j=0;j<Len;j++){
if(islower(Name[i][j])){
Name[i][j] = toupper(Name[i][j]);
}
}
puts(Name[i]);
}
return 0;
}
有幾個ASCII要記
對應十進位ASCII Code
0 -> 48
A -> 65
a -> 97
藉此就能反推大小寫轉換差32了
#include<stdio.h>
int main(int argc, char *argv[]){
char work[3]; /* 輸入文字 */
int w;
int i,j;
int in;
char c[8];
char a;
char S_word[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; /*小寫*/
char B_word[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; /*大寫*/
for(in=0; in<=10; in++){
scanf("%s",&work[in]);
for(w=0; w<=25; w++){
j = j+1;
/* 小寫變大寫轉換 */
if(work[in]==S_word[w]){
S_word[w] = B_word[w];
work[in] = B_word[w];
}
/* 大寫變小寫轉換 */
if(work[in]==B_word[w]){
B_word[w] = S_word[w];
work[in] = S_word[w];
}
c[0] = '*';
c[1] = '*';
c[2] = '*';
c[3] = '*';
if(j==1){
c[4] = work[0];
a = (c[0]);
}
if(j==2){
c[5] = work[1];
a = (c[1]);
}
if(j==3){
c[6] = work[2];
a = (c[2]);
}
if(j==4){
c[7] = work[3];
a = (c[3]);
j = 0; //這行要放在最後一個敘述唷!!
}
}
printf("%s",&a);
}
return 0;
}
設計的大小寫轉換程式碼,各位可以參考看看,感恩。