1035. Password (20)

本文介绍了一个程序设计案例,用于检查并修正容易混淆的用户密码,如将1替换为@、0替换为%等,以提高密码的独特性和可读性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:

原题目

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N (<= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

Output Specification:

For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line "There are N accounts and no account is modified" where N is the total number of accounts. However, if N is one, you must print "There is 1 account and no account is modified" instead.

Sample Input 1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
Sample Output 1:
2
Team000002 RLsp%dfa
Team000001 R@spodfa
Sample Input 2:
1
team110 abcdefg332
Sample Output 2:
There is 1 account and no account is modified
Sample Input 3:
2
team110 abcdefg222
team220 abcdefg333
Sample Output 3:
There are 2 accounts and no account is modified
注意:1个是 is count 多个是 are counts,代码如下
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
struct sno{
	char name[100];
	char pass[100];
	int flag;
};

int main()
{
	sno ll[1004];
	int n;
	int count = 0;
	while (scanf("%d", &n) != EOF){
		for (int i = 0; i < n; i++)
		{
			scanf("%s%s", ll[i].name, ll[i].pass);
			ll[i].flag = 1;
			int s = strlen(ll[i].pass);
			for (int j = 0; j < s; j++)
			{
				if (ll[i].pass[j] == '0')
				{
					ll[i].pass[j] = '%';
					ll[i].flag = 0;
				}
				if (ll[i].pass[j] == '1')
				{
					ll[i].pass[j] = '@';
					ll[i].flag = 0;
				}
				if (ll[i].pass[j] == 'l')
				{
					ll[i].pass[j] = 'L';
					ll[i].flag = 0;
				}
				if (ll[i].pass[j] == 'O')
				{
					ll[i].pass[j] = 'o';
					ll[i].flag = 0;
				}
			}
			if (ll[i].flag == 0)
			{
				count++;
			}
		}

		int s = 0;
		for (int i = 0; i < n; i++)
		{
			if (ll[i].flag == 0)
			{
				if (s == 0)printf("%d\n", count);
				printf("%s %s\n", ll[i].name, ll[i].pass);
				s = 1;
			}
		}
		if (s == 0)
		{
			if (n <= 1)printf("There is %d account and no account is modified\n",n);
			else printf("There are %d accounts and no account is modified\n", n);
		}
	}
	system("pause");
	return 0;
}

int format_unknown_device(const char *device, const char* path, const char *fs_type) { 991 LOGW("clean the partition %s in the rm - rf way \n", path); 992 993 static char tmp[PATH_MAX]; 994 bool DEBUG = false; 995 if (strcmp(path, "/data") == 0) { 996 char property_wipemedia[PROPERTY_VALUE_MAX+1]; 997 persist_property_get("persist.sys.wipemedia", property_wipemedia, "0"); 998 printf("In format_unknown_device funtion, persist.sys.wipemedia is %s \n", property_wipemedia); 999 1000 ensure_path_mounted(path); 1001 1002 //Yang.Li@PSW.AD.Recovery.1596362, 2018/11/26, Add for master clear in FBE 1003 /*if (encrypt_type == 1) { 1004 int pw_type = get_password_type(0); 1005 if (pw_type > 0) { 1006 bool reset_pwd_ret = false; 1007 char secret_buffer[65] = {0}; 1008 bool ret = get_secret_hex((uint8_t*)secret_buffer); 1009 secret_buffer[64] = 0; 1010 std::string secret_hex = secret_buffer; 1011 reset_pwd_ret = fscrypt_clear_user_key_auth(0, 0, "!", secret_hex); 1012 printf("fscrypt_clear_user_key_auth, reset_pwd_ret=%d \n", reset_pwd_ret); 1013 reset_pwd_ret = fscrypt_fixate_newest_user_key_auth(0); 1014 printf("fscrypt_fixate_newest_user_key_auth is %d\n", reset_pwd_ret); 1015 } 1016 }*/ 1017 1018 #ifdef OPLUS_FEATURE_RECOVERY_BOOT 1019 //Yang.Li@ANDROID.UPDATABILITY, 2016/09/18, Add for deleting other special data when wipe sdcard 1020 /*if (strcmp(property_wipemedia, "0") != 0) { 1021 //Xuefeng.Peng@PSW.AD.Recovery.1880299, 2019/03/06, Add for deleting user 999 1022 fscrypt_unlock_user_key(999, 10, "!", "!"); 1023 fscrypt_destroy_user_key(999); 1024 fscrypt_destroy_user_storage("", 999, STORAGE_FLAG_DE | STORAGE_FLAG_CE); 1025 sprintf(tmp, "rm -rf /data/misc/vold/user_keys/ce/999"); 1026 __system(tmp); 1027 sprintf(tmp, "rm -rf /data/misc/vold/user_keys/de/999"); 1028 __system(tmp); 1029 //end Xuefeng.Peng modify 1030 LOGW("persist.sys.wipemedia isn't 0, delete /data/media/999.......\n"); 1031 sprintf(tmp, "rm -rf /data/media/999/*"); 1032 __system(tmp); 1033 sprintf(tmp, "rm -rf /data/media/999/.*"); 1034 __system(tmp); 1035 1036 //delete actual data in /sdcard/Android/obb 1037 sprintf(tmp, "rm -rf /data/media/obb/*"); 1038 __system(tmp); 1039 sprintf(tmp, "rm -rf /data/media/obb/.*"); 1040 __system(tmp); 1041 }*/ 1042 #endif /* OPLUS_FEATURE_RECOVERY_BOOT */ 1043 1044 if (strcmp(property_wipemedia, "3") == 0) { 1045 LOGW("persist.sys.wipemedia is 3, only delete /data/media/0.......\n"); 1046 //sprintf(tmp, "cd /data/media/0 ; for f in $(ls -a); do rm -rf $f; done"); 1047 sprintf(tmp, "rm -rf /data/media/0/*"); 1048 __system(tmp); 1049 //#wangzequan@EXP.sysFramework.recovery, 2015/08/24, modify for bug684379:factory mode cannot remove hidden files 1050 sprintf(tmp, "rm -rf /data/media/0/.*"); 1051 __system(tmp); 1052 return 0; 1053 } 1054 1055 if (strcmp(property_wipemedia, "2") == 0) { 1056 static char property_auto_masterclear[PROPERTY_VALUE_MAX+1]; 1057 property_get("persist.sys.auto.masterclear", property_auto_masterclear, ""); 1058 printf("In format_unknown_device funtion, persist.sys.auto.masterclear is %s \n", property_auto_masterclear); 1059 1060 if (strcmp(property_auto_masterclear, "1") == 0) { 1061 printf("In format_unknown_device funtion, echo 1 > %s \n", "/data/engineermode/engineermode_masterclear_flag"); 1062 sprintf(tmp, "echo 1 > %s", "/data/engineermode/engineermode_masterclear_flag"); 1063 __system(tmp); 1064 } 1065 1066 DEBUG = true; 1067 LOGW("before Formatting /data/media/0.......\n"); 1068 //printDir("/data/media/0"); 1069 //ensure_path_mounted("/system"); 1070 format_except_builtin(); 1071 LOGW("after Formatting /data/media/0.......\n"); 1072 //printDir("/data/media/0"); 1073 1074 sprintf(tmp, "toybox find /data/media/0/* | toybox sed 's#/data/media/0/##g' | toybox sort > %s", "/data/engineermode/data_file_after_clear.txt"); 1075 __system(tmp); 1076 } 1077 1078 //ifdef OPLUS_FEATURE_RECOVERY_BOOT 1079 //Yang.Li@ANDROID.UPDATABILITY.1122242, 2018/01/25, Remove for transfer the task of deleting /data/app built-in apks to PMS 1080 /*if (access("/data/app", F_OK) != -1) { 1081 LOGW("rm /data/app exception built-in apk \n"); 1082 sprintf(tmp, "cd /data/app; ls | toybox sort > allfilelist; cat builtinlist | toybox sort > builtinlist_sort; cat builtinlist_sort >> %s; cat allfilelist >> %s; toybox diff -a builtinlist_sort allfilelist >> %s", TEMPORARY_LOG_FILE, TEMPORARY_LOG_FILE, TEMPORARY_LOG_FILE); 1083 __system(tmp); 1084 sprintf(tmp, "cd /data/app; toybox diff -a builtinlist_sort allfilelist | toybox grep ^+ | toybox sed '1d'| toybox sed 's/+//g' | toybox grep -v builtinlist_s | toybox grep -v allfilelist | toybox grep -v packages.xml | while read line; do echo \"$line\" >> %s; rm -rf \"$line\"; done" , TEMPORARY_LOG_FILE); 1085 __system(tmp); 1086 } else { 1087 LOGW("error access /data/app"); 1088 }*/ 1089 //#endif /* OPLUS_FEATURE_RECOVERY_BOOT */ 1090 #ifdef OPLUS_FEATURE_RECOVERY_BOOT 1091 //#wangzequan@EXP.sysFrameworks.recovery, 2016/03/04, modify for avoiding data mount fail, clear system files 1092 if (access("/data/media", F_OK) != -1) { 1093 //Yang.Li@PSW.AD.Recovery.1596362, 2018/12/03, Modify for master clear in FBE or FDE. 1094 if (encrypt_type == 1) { 1095 sprintf(tmp, "cd /data ; for f in $(ls -a | grep -E -v \"^(misc|media|\.layout_version|app|reserve|gr|engineermode|theme_bak|data|opponvitems|etc|format_unclear|dalvik-cache|unencrypted)$\"); do rm -rf $f; done"); 1096 __system(tmp); 1097 1098 //Delete /data/misc except /data/misc/vold/user_keys 1099 sprintf(tmp, "cd /data/misc; ls -a | grep -E -v \"^(vold|gatekeeper)$\" | xargs rm -rf; cd /data/misc/vold; ls -a | grep -v \"^user_keys$\" | xargs rm -rf;"); 1100 __system(tmp); 1101 __system("rm -rf /data/misc/vold/user_keys/test_secret"); 1102 1103 //Delete Multi-User data file 1104 sprintf(tmp, "cd /data ; for f in $(ls -a | grep -E \"^(misc_ce|system_ce|vendor_ce|user|media|misc_de|system_de|user_de|vendor_de)$\"); do cd $f; ls -a | grep -E \"^([1-9][0-9]*){1,3}$\" | xargs rm -rf; cd ../; done"); 1105 __system(tmp); 1106 //Delete /data/misc/vold/user_keys/ce and /data/misc/vold/user_keys/de except 0 1107 sprintf(tmp, "cd /data/misc/vold/user_keys/ce; ls -a | grep -v \"^0$\" | xargs rm -rf; cd /data/misc/vold/user_keys/de; ls -a | grep -v \"^0$\" | xargs rm -rf;"); 1108 __system(tmp); 1109 } else { 1110 sprintf(tmp, "cd /data ; for f in $(ls -a | grep -E -v \"^(media|\.layout_version|app|reserve|gr|engineermode|theme_bak|data|opponvitems|etc|format_unclear|dalvik-cache)$\"); do rm -rf $f; done"); 1111 __system(tmp); 1112 } 1113 1114 #ifdef OPLUS_FEATURE_RECOVERY_BOOT 1115 //#Fangfang.Hui@ANDROID.UPDATABILITY, 2017/02/13, Add for delete /data/data/ directory here, only delete com.coloros.encryption when /data/media/0 is deleted 1116 if (strcmp(property_wipemedia, "3") == 0) { 1117 __system("rm -rf /data/data/com.coloros.encryption"); 1118 } else { 1119 //WangFuJiang@ANDROID.CUSTOMIZE, 2020/05/19, reserve passwordmanager 1120 if (noWipeData()) { 1121 sprintf(tmp, "rm -rf /data/data"); 1122 } else { 1123 sprintf(tmp, "cd /data/data ; for f in $(ls -a | grep -E -v \"(mb.passwordmanager)$\"); do rm -rf $f; done"); 1124 } 1125 __system(tmp); 1126 } 1127 #endif /*OPLUS_FEATURE_RECOVERY_BOOT*/ 1128 } else { 1129 LOGW("error access /data/media"); 1130 } 1131 #endif 1132 1133 if (strcmp(property_wipemedia, "1") == 0) { 1134 LOGW("persist.sys.wipemedia is 1, delete /data/media/0 also .......\n"); 1135 sprintf(tmp, "rm -rf /data/media/0/*"); 1136 __system(tmp); 1137 //#wangzequan@EXP.sysFramework.recovery, 2015/08/24, modify for bug684379:factory mode cannot remove hidden files 1138 sprintf(tmp, "rm -rf /data/media/0/.*"); 1139 __system(tmp); 1140 } 1141 1142 // if the /data/media sdcard has already been migrated for android 4.2, 1143 // prevent the migration from happening again by writing the .layout_version 1144 struct stat st; 1145 if (0 == lstat("/data/media/0", &st)) { 1146 char* layout_version = "2"; 1147 FILE* f = fopen("/data/.layout_version", "wb"); 1148 if (NULL != f) { 1149 fwrite(layout_version, 1, 2, f); 1150 fclose(f); 1151 } else { 1152 LOGW("error opening /data/.layout_version for write.\n"); 1153 } 1154 } else { 1155 LOGW("/data/media/0 not found. migration may occur.\n"); 1156 } 1157 } else { 1158 ensure_path_mounted(path); 1159 LOGW("Formatting data.......\n"); 1160 sprintf(tmp, "rm -rf %s/*", path); 1161 __system(tmp); 1162 sprintf(tmp, "rm -rf %s/.*", path); 1163 __system(tmp); 1164 } 1165 1166 if (DEBUG) { 1167 LOGW("after Formatting data.......\n"); 1168 //printDir("/data"); 1169 char buf[20] = ""; 1170 FILE* f = fopen("/data/.layout_version", "r"); 1171 if (NULL != f) { 1172 fread(buf, 1, sizeof(buf)-1 , f); 1173 LOGW("/data/.layout_version = %s.......\n", buf); 1174 fclose(f); 1175 } 1176 } 1177 ensure_path_unmounted(path); 1178 return 0; 1179 } 1180 1181 extern int getBuilitinList(); 1182 1183 //#Fangfang.Hui@Swdp.Android.Recovery, 2016/05/24, Add for save some last_logs to memory and restore them later when wipe cache 1184 typedef struct _saved_log_file { 1185 char* name; 1186 struct stat st; 1187 unsigned char* data; 1188 struct _saved_log_file* next; 1189 } saved_log_file;
最新发布
08-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值