• poj3157


    字符串处理

    View Code
    #include <iostream>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cstdio>
    using namespace std;

    string st;

    int main()
    {
    //freopen("t.txt", "r", stdin);
    cin >> st;
    bool java = false;
    bool cpp = false;
    if (st[0] == '_')
    {
    cout
    << "Error!" << endl;
    return 0;

    }
    for (int i = 0; i < st.length(); i++)
    if (st[i] >= 'A' && st[i] <= 'Z')
    {
    if (i == 0)
    {
    cout
    << "Error!" << endl;
    return 0;
    }
    java
    = true;
    break;
    }
    if (st.find('_') != string::npos)
    cpp
    = true;
    if (cpp && java)
    {
    cout
    << "Error!" << endl;
    return 0;
    }
    if (cpp)
    {
    if (st.find("__") != string::npos || st[st.length() - 1] == '_')
    {
    cout
    << "Error!" << endl;
    return 0;
    }
    for (int i = 0; i < st.length(); i++)
    if (st[i] == '_')
    {
    st.erase(i,
    1);
    st[i]
    = st[i] - 'a' + 'A';
    }
    }
    else
    {
    for (int i = 0; i < st.length(); i++)
    if (st[i] >= 'A' && st[i] <= 'Z')
    {
    st[i]
    = st[i] - 'A' + 'a';
    st.insert(i,
    "_");
    }
    }
    cout
    << st << endl;
    return 0;
    }
  • 相关阅读:
    寒假作业1
    秋季学习总结
    记叙在人生路上对你影响最大的三位老师
    2019年春季学期第二周作业
    币值转换
    第九周作业
    第八周作业
    第七周作业
    第六周作业
    第五周作业
  • 原文地址:https://www.cnblogs.com/rainydays/p/2178036.html
Copyright © 2020-2023  润新知