zoukankan      html  css  js  c++  java
  • hdu 2629 Identity Card string类用于c的字符串函数上

        这几天做ACM Step,比较不错,在做一道题的时候,我用的是string,函数用的是strncmp,说参数不匹配,看了看函数原型,参数是const char *,而我用的是string,需要转换一下:

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

     #include<iostream>



    using namespace std;
    int main()
    {
        
    int n,i,temp;
        
    char s[50];
        
    string regional[8]={"Zhejiang","Beijing","Taiwan","Hong Kong","Macao","Tibet","Liaoning","Shanghai"};
        
    string id[8= {"33""11""71""81""82""54""21""31"};
        cin
    >>n;

                     
    while(n--)
                     {
                               cin
    >>s;
                               cout
    <<"He/She is from ";
                               
    for(i=0;i<8;i++)
                               {
                                                
    if (strncmp(s, id[i].c_str(), 2== 0)
                                               {
                                                                cout
    <<regional[i];
                                                                
    break;
                                               }
                               }


                         cout
    <<",and his/her birthday is on "<<s[10]<<s[11]<<","<<s[12]<<s[13]<<","<<s[6]<<s[7]<<s[8]<<s[9]<<" based on the table."<<endl;

                 }

    }
  • 相关阅读:
    纪念,暑假的招手
    #include <filename.h> 和 #include“filename.h” 有什么区别
    const 有什么用途
    指针和引用的区别
    main函数执行前后还会发生什么
    exit()和return语句的区别
    电子邮件中域名的使用和建议
    提升电子邮件产能的4个重要指标
    发件人信誉度培养
    tokyo cabinet相关站点文档
  • 原文地址:https://www.cnblogs.com/anderson0/p/2039679.html
Copyright © 2011-2022 走看看