hdu 1161 Eddy's mistakes

http://acm.hdu.edu.cn/showproblem.php?pid=1161

本题主要运用的就是大小写的转换;

我写的代码:

#include<iostream>
#include <string>
#include <ctype.h>
using namespace std;
int main(int argc, char *argv[])
{
    string a;
    char c;
    while( getline(cin,a)){
      for(int i=0;i<a.length();i++)
    {    c=a[i];
        if(isupper(c)) c=tolower(c);
        cout<<c;
    }
    cout<<endl;
    }
  
    return 0;
}

 

 

 

 

老师教授的更简单的方法:所占字节比较少

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    char s[1001];
    while(cin.getline(s,1000))
         cout<<  strlwr(s)<<endl;
                       
    return 0;
}


/*

  strlwr

  原型:extern char *strlwr(char *s);
  用法:#include <string.h>
  功能:将字符串s转换为小写形式
  说明:只转换s中出现的大写字母,不改变其它字符。返回指向s的指针。
  举例:
  // strlwr.c
  #include <syslib.h>
  #include <string.h>
  main()
  {
  char *s="Copywrite 1999-2000 GGV Technologies";
  clrscr();
  printf("%s",strlwr(s));
  getchar();
  return 0;
*/

posted @ 2013-04-02 19:40  90后程序媛  阅读(296)  评论(0编辑  收藏  举报