hdu2573 大小寫識別

很簡單的一道題目,還是出現了一個小問題 !的運算級比%運算高,以後要小心...

 

#include <iostream>
using namespace std;
char num[101];
int main()
{
 int t;
 cin>>t;
 while(t--)
 {
  int n;
  cin>>n;
  int top=-1;
  int tag=0;//tag爲偶數標示大寫關閉
  
  getchar();//去掉後面的換行
  char input[10];
  char temp[6];
  while(n--)
  {
   gets(input);
   if(strcmp(input,"Caps")==0){tag++;continue;}
   strncpy(temp,input,5),temp[5]='/0';
   if(strcmp(temp,"Shift")==0)
   {
    if(!(tag%2))num[++top]=input[6]-32;
    else num[++top]=input[6];
   }
   else //單個字符
   {
    if(!(tag%2))num[++top]=input[0];
    else num[++top]=input[0]-32;
   }  
  }
  for(int i=0;i<=top;i++)
   cout<<num[i];
  cout<<endl;  
 }
       
 return 0;
}

發佈了39 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章