游客 Signup | Login
中文 | En

1475 - 《C语言程序设计》江宝钏主编-习题5-9-模拟登录

编写程序模拟简单的密码登录,首先从键盘输入名字和密码,若密码正确则给出问候语。

若密码不正确,则给出错误提示,并允许再次输入,直到输入正确的密码或0结束。

用户名随意,不超过10个字节。

密码123456

Input

用户名,和若干次密码。

Output

若密码正确则输出:

Hello 用户名换行

并退出

若错误则输出:

Wrong Password!换行

并再次输入判断

若密码为0则在输出正确与否的结果后退出。

Examples

Input

tom
123
123456

Output

Wrong Password!
Hello tom

Solution C

#include <stdio.h>
int main(void)
{
	char a[10],p[20];
	int s;
	scanf("%s",&a);
	while(1) 
	{
		getchar();
		scanf("%d",&s);
		if (s==123456)
		{
			printf("Hello %s\n",a);
			break;
		}
		else if (s==0)
		{
			printf("Wrong Password!");
			break;
		}
		else
		{
			printf("Wrong Password!\n");
		}
	}

	return 0;
}

Solution C++

#include<iostream>
#include<string>
using namespace std;
int main()
{
	string name,pword;
	getline(cin,name);
	bool flag=false;
	do
	{
		getline(cin,pword);
		if (pword=="123456")
		{
			flag=true;
			cout<<"Hello "<<name<<endl;
			return 0;
		}
		else if (pword=="0")
		{
			cout<<"Wrong Password!"<<endl;
			return 0;
		}
		else cout<<"Wrong Password!"<<endl;
	} while (!flag);
}
Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题