高手帮忙,基础问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 11:50:59
有一类编程经常要用到字符串输入校对,请以下面的例子讲讲怎么实现,感谢万分:

用一个二维数组存国家与首都,提示用户输入一个城市的首都,和数组中的答案校对,提示用户回答是否正确。

char *citys[50] =
{
"beijing",
"guangzhou",
"shanghai"
};
char name[] = "bei";

for(int i = 0; i < 3; i++)
{
if(!strcmp(citys[i], name))
{
printf("right!\n");
}
}
}

main(){
char *country[]={"china","beijin","法国","巴黎","英国","伦敦","",""};
char temp[20],**sp;
int i=1;
sp=country;
printf("\n输入一个城市的首都:");
gets(temp);
while(*(p[i])){
if(strcmp(p[i],temp)==0)
printf("your answer is right .%s",p[i-1]);
i+=2;
}

用下标奇数对应国家,偶数对应首都.
搜寻数组时用i=i+2来保证和每个首都相比较.
不明白加我百度,问

#include<iostream>
#include<string>
using namespace std;
int main()
{
string couCap[5][2];
string input;
cout<<"请输入5个国家的国家名与首都"<<endl;