【问题标题】:Why isnt my code working for problem "cAPS lOCK" on code forces为什么我的代码不能解决代码强制问题“cAPS 锁定”问题
【发布时间】:2022-06-16 21:23:49
【问题描述】:

您好,我正在尝试解决“cAPS lOCK”问题,当我输入“cAPS”时,它应该打印“Caps”,但它会打印“caPScapScapscaps”,即使我在以下情况下暂停程序以停止程序条件为真,它继续运行这是我的代码。

 #include <iostream>

using namespace std;

 int main()
{
 //  -if all letters are capital:
  //all of them become small
//-if all letters EXCEPT the first letters are capital:
  //all of them become small except the first one becomes capital
//-everything else:
 //keep the word as it is
    string s;
    cin>>s;
    int c=0;
    for(int i=0;s[i]!='\0';i++)
    {
       c++;
    }
   for(int j=0;j<c;j++)
   {
       if(s[j]>=65 && s[j]<=90)
   {
       s[j]=s[j]+32;
       cout<<s;
       break;
   }
   for(int k=1;k<c;k++)
      {
      if(s[k]>=65 && s[k]<=90)
   {
       s[k]=s[k]+32;
       cout<<s;
       break;
       }
       }
 
   
      }
     cout<<s;
     }

【问题讨论】:

  • 保持不一致的缩进将使不平衡括号的问题更难发现。修复它,错误可能会更加明显。

标签: c++ c++17


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-01
  • 1970-01-01
  • 2013-05-23
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 2019-06-06
相关资源
最近更新 更多