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;

             }

}
原文地址:https://www.cnblogs.com/anderson0/p/2039679.html