首页 > 试题广场 >

编写一个程序,读取键盘输入,直到遇到@符号为止,并回显输入(

[问答题]
编写一个程序,读取键盘输入,直到遇到@符号为止,并回显输入(数字除外),同时将大写字符转换为小写,将小写字符转换为大写(别忘了cctype函数系列)。
#include<iostream>
#include<cctype>
int main()
{
    using namespace std;
    char ch;
    while((ch=cin.get())!='@')
    {
        if(isdigit(ch))
            continue;
        if(islower(ch))
        {   
            cout<<(char)toupper(ch);
        }
        else if(isupper(ch))
        {
            cout<<(char)tolower(ch);
        }
    }
    return 0;

发表于 2021-08-14 18:28:19 回复(0)
#include<iostream>
#include<cctype>

using namespace std;

typedef char ElemType;
typedef int Status;


typedef struct Node
{
    ElemType data;
    struct  Node *next;
}Node;


int main(){

    Node *head = new Node;
    head->next = NULL;

    char sign;
    Node *p= head;

    while(cin>>sign,sign!='@'){

        Node *c = new Node;
        if (islower(sign)){
            sign = toupper(sign);
        }else if(isupper(sign)) {
            sign = tolower(sign);
        }         c->data = sign;
        c->next = p->next; 
        p->next = c;
    }
    
     while(head->next!=NULL){

        head = head->next;
        cout<<" -> "<<head->data;

    }
    
    cout<<endl;
    system("pause");
    return 0;
}


编辑于 2021-04-16 15:59:49 回复(0)
#include <iostream>
#
include <string>
#include <cctype>

// cctype头文件常用函数,字符判断处理的库函数
// isalnum()  如果参数是字母数字,即字母或者数字,函数返回true
// isalpha()  如果参数是字母,函数返回true
// iscntrl()  如果参数是控制字符,函数返回true
// isdigit()  如果参数是数字(0-9),函数返回true
// isgraph()  如果参数是除空格之外的打印字符,函数返回true
// islower()  如果参数是小写字母,函数返回true
// isprint()  如果参数是打印字符(包括空格),函数返回true
// ispunct()  如果参数是标点符号,函数返回true
// isspace()  如果参数是标准空白字符,如空格、换行符、水平或垂直制表符,函数返回true
// isupper()  如果参数是大写字母,函数返回true
// isxdigit() 如果参数是十六进制数字,即0-9、a-f、A-F,函数返回true
// tolower()  如果参数是大写字符,返回其小写,否则返回该参数
// toupper()  如果参数是小写字符,返回其大写,否则返回该参数

// 将字符加在字符串后面的方法
// 1.string b;
//      char a;
//   b = b + a;
// 2.b.append(1, a); 

// 只有在输入完数据再按回车键后,该行数据才被送入键盘缓冲区,形成输入流,
// 提取运算符“>>”才能从中提取数据。需要注意保证从流中读取数据能正常进行。
int main(int argc, char const *argv[])
{
    using namespace std;
    char a;
    cin.get(a);
    string b;
    while (a != '@') {
        if (islower(a)) {
            a = toupper(a);
        } else if (isupper(a)) {
            a = tolower(a);
        }
        b += a;
        cin.get(a);
    }
    cout << "end:" << b;
    return 0;
}
// 存在问题,缓冲数据等换行符结束,但是应该用户输入到@就结束,由于使用cin无法解决
发表于 2020-03-11 10:06:41 回复(0)

#include <stdlib.h>
#include
#include
using namespace std;
int main()
{
    char tmp;
    cin.get(tmp);
    while (tmp !='@')
    {
        if (!isdigit(tmp)) {
            if (tmp >= 'a' && tmp <= 'z') {
                tmp = toupper(tmp);
            }else if (tmp >= 'A' && tmp <= 'Z') {
                tmp = tolower(tmp);
            }
            cout << tmp;
        }
        cin.get(tmp);
    }

    cout << endl;
    return 0;

}

发表于 2019-07-23 16:39:14 回复(0)