首页 > 试题广场 >

密码验证

[编程题]密码验证
  • 热度指数:10644 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

用户登录网站,通常需要注册,一般需要输入两遍密码。请编程判断输入的两次密码是否一致,一致输出“same”,不一致输出“different”



输入描述:
每行有两个用空格分开的字符串,第一个为密码,第二个为重复密码。


输出描述:
每组输出一个字符串(“same”或“different”)。
示例1

输入

abc abc

输出

same
#include<stdio.h>
#include<string.h>
int main()
{
     char a[100],b[100];
    while(scanf("%s %s",a,b)!=EOF)
    {
        if(strcmp(a,b)==0)
        {
            printf("same");
        }
        else
            printf("different");
    }
}
发表于 2021-11-28 17:00:19 回复(0)
#include <stdio.h>
#include <string.h>


int main()
{
    char a[100],b[100];
    while(scanf("%s %s",a,b) != EOF)
    {
        int i;
        int flag = 0;
        for(i=0;(a[i] !='\0')||(b[i]!='\0');i++)
        {
            if(a[i] != b[i])
            {
                flag = 1;
                break;
            }
        }
        if(flag == 1)
            printf("different\n");
        else
            printf("same\n");
            
                
    }
    
    return 0;
}

发表于 2021-09-06 14:43:57 回复(0)
#include<iostream>
#include<string>
using namespace std;
int main(){
    string a,b;
    cin>>a;
    cin>>b;
    if(a==b){
        cout<<"same";
    }else{
        cout<<"different";
    }
}
比较简单的话 可以直接比较大小
发表于 2021-01-09 21:09:03 回复(0)
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char pass1[10],pass2[10];
    scanf("%s %s",pass1,pass2);
    string s1 = pass1;
    string s2 = pass2;
    if(s1.compare(s2) == 0){
        cout<<"same"<<endl;
    }
    else
        cout<<"different"<<endl;
    
}

发表于 2020-09-30 22:24:53 回复(0)
#include <stdio.h>
(737)#include <string.h>
int main()
{
    char str1[105],str2[105];
    scanf("%s %s",str1,str2);
    int len1=strlen(str1),len2=strlen(str2);
    int flag=1;
    if(len1!=len2) flag=0;
    else{
        int i,j;
        for(i=0,j=0;i<len1&&j<len2;i++,j++){
            if(str1[i]!=str2[j]){
                flag=0;
                break;
            }
        }
    }
    if(flag) printf("same\n");
    else printf("different\n");
}

发表于 2020-04-10 20:14:22 回复(0)
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
class P
{
    public static void Main()
    {
        var item = ReadLine().Split();
        if(item[0]==item[1])
            Write("same");
        else
            Write("different");

    }
}
//

发表于 2020-03-23 16:59:40 回复(0)
#include <stdio.h>
#include <string.h>
#define LEN 20

int main(void)
{
    char a[LEN], b[LEN];
    
    while (scanf("%19s %19s", a, b) != EOF)
    {
        if (0 == strcmp(a, b))
        {
            puts("same");
        }
        else
        {
            puts("different");
        }
    }
    
    return 0;
}
//注意scanf的输入限制, 会内存溢出;
编辑于 2020-04-18 22:38:20 回复(0)
#include <stdio.h>
#include <string.h>
#define MAX 20
int main() {
    char s1[MAX] = {0};
    char s2[MAX] = {0};
    scanf("%s %s", s1, s2);
    int ret = strcmp(s1, s2);
    if (ret == 0) printf("same\n");
    else printf("different\n");

    return 0;
}

发表于 2023-03-19 17:54:01 回复(0)
#include <stdio.h>
#include <string.h>
int main() 
{
    char arr1[100],arr2[100];
    scanf("%s %s",arr1,arr2);
    if(strcmp(arr1,arr2)==0)
    {
        printf("same\n");
    }
    else
    {
        printf("different\n");
    }
    
    return 0;
}

发表于 2023-01-01 18:39:19 回复(0)
#include <stdio.h>
#include <string.h>

int main()
{
  char s1[16];
  char s2[16];
  while(scanf("%s %s", &s1, &s2) != EOF)
  {
     if(strcmp(s1, s2) == 0 )
          printf("same\n");
     else 
          printf("different\n");
  }
  return 0;
}

发表于 2022-01-09 23:17:38 回复(0)
#include<stdio.h>
#include<string.h>
int main()
{
    char a[10]={0},b[10]={0};
    while(scanf("%s %s",a,b)!=EOF)
    {
        if(strcmp(a,b)==0)
            printf("same\n");
        else
            printf("different\n");
    }
    return 0;
}

发表于 2021-12-26 20:13:22 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] strings = str.split(" ");
        if (strings[0].contains(strings[1])){
            System.out.println("same");
        }else {
            System.out.println("different");
        }
    }
}

发表于 2021-12-20 01:34:41 回复(0)
# include<bits/stdc++.h>
using namespace std;
int main()
{
    char password1[20];
    char password2[20];
    cin >> password1 >> password2;
    if(strcmp(password1,password2)==0)
        cout << "same\n";
    else
        cout << "different\n";
    return 0;
}

发表于 2021-12-19 14:48:33 回复(0)
#include <iostream>

using namespace std;

int main()
{
    string str1;
    string str2;
    cin >> str1 >> str2;
    if(str1 == str2)
    {
        cout << "same" << endl;
    }
    else
    {
        cout << "different" << endl;
    }
}
发表于 2021-10-29 11:18:25 回复(0)
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        
        String s1=input.nextLine();
        
        String[] a=s1.split(" ");
        
        if(a[0].equals(a[1]))
            System.out.println("same");
        else 
            System.out.println("different");
    }
}

发表于 2021-10-28 10:48:44 回复(0)
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s1;
    string s2;
    cin>>s1>>s2;
    if(s1==s2)
    {
        cout<<"same";
    }
    else
    {
        cout<<"different";
    }
    return 0;
}
发表于 2021-10-18 12:24:11 回复(0)
#include<stdio.h>
int main()
{
    char a[20],b[20];
    scanf("%s %s",a,b);
    if(strcmp(a,b)==0)printf("same\n");
    else printf("different\n");
    
    return 0;
}


发表于 2021-10-05 17:45:38 回复(0)
#include <stdio.h>
#include <string.h>
int main()
{
    char pass1[20],pass2[20];
    scanf("%s %s",&pass1,&pass2);
    if(strcmp(pass1,pass2)==0) printf("same");
    else                       printf("different");
    return 0;
}

发表于 2021-09-17 16:25:00 回复(0)
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().spilt(" ");
        if(str[0].equals(str[1])){
            System.out.println("same");
        }else{
            System.out.prtinln("different");
        }
    }
}

发表于 2021-04-17 15:38:18 回复(0)
解法一:
let str = readline();

let a = str.split(" ")[0];
let b = str.split(" ")[1];

if (a === b) {
      console.log('same')
} else {
     console.log('different')
}

发表于 2021-03-10 00:07:32 回复(0)

问题信息

上传者:牛客309119号
难度:
37条回答 2249浏览

热门推荐

通过挑战的用户

查看代码
密码验证