题目来源:http://noi.openjudge.cn/ch0107/22/
C++ string类的比较用 str1.compare(str2)
str1 < str2: -1
str1==str2: 0
str1 > str2: +1
22:紧急措施
总时间限制:1000ms 内存限制:65536kB
描述
近日,一些热门网站遭受黑客入侵,这些网站的账号、密码及email的数据惨遭泄露。你在这些网站上注册若干账号(使用的用户名不一定相同),但是注册时使用了相同的email。你此时拿到了那份泄露的数据,希望尽快将自己的密码更改。策略如下:根据email找到你的用户名和密码,然后更改密码。更改的规则为:小写和大写交换,非字母字符保持不变。
输入
第一行为你的email地址,长度不超过50个字符且只包含字母、数字和‘@’符号。
第二行为账号数N,N(0 < N < 10000)。
接下来N行,每行表示一个账号,格式为:
用户名密码email
它们之间用单个空格分开。用户名、密码、email均不含空格,且长度不超过50个字符。
输出
有若干行,每行为你的一个账号,包括:你的账号,修改后的密码(之间用单个空格分隔)。
如果没有你的账号,则输出empty。
样例输入
样例输入1: [email protected] 5 helloKitty iLoveCats [email protected] 2012 maya2012 [email protected] KittyCat 5iKitty [email protected] program password [email protected] whoAmi Feb.29$ [email protected] 样例输入2: [email protected] 1 2012 maya2012 [email protected]
样例输出
样例输出1: helloKitty IlOVEcATS KittyCat 5IkITTY whoAmi fEB.29$ 样例输出2: empty
来源
医学部计算概论2011年期末考试(谢佳亮)
-----------------------------------------------------
解题思路
模拟
-----------------------------------------------------
代码
//B:紧急措施 //总时间限制: 1000ms 内存限制: 65536kB //描述 //近日,一些热门网站遭受黑客入侵,这些网站的账号、密码及email的数据惨遭泄露。你在这些网站上注册若干账号(使用的用户名不一定相同),但是注册时使用了相同的email。你此时拿到了那份泄露的数据,希望尽快将自己的密码更改。策略如下:根据email找到你的用户名和密码,然后更改密码。更改的规则为:小写和大写交换,非字母字符保持不变。 // //输入 //第一行为你的email地址,长度不超过50个字符且只包含字母、数字和‘@’符号。 //第二行为账号数N,N(0 < N < 10000)。 //接下来N行,每行表示一个账号,格式为: //用户名 密码 email //它们之间用单个空格分开。用户名、密码、email均不含空格,且长度不超过50个字符。 //输出 //有若干行,每行为你的一个账号,包括:你的账号,修改后的密码(之间用单个空格分隔)。 //如果没有你的账号,则输出empty。 //样例输入 //样例输入1: //[email protected] //5 //helloKitty iLoveCats [email protected] //2012 maya2012 [email protected] //KittyCat 5iKitty [email protected] //program password [email protected] //whoAmi Feb.29$ [email protected] // //样例输入2: //[email protected] //1 //2012 maya2012 [email protected] //样例输出 //样例输出1: //helloKitty IlOVEcATS //KittyCat 5IkITTY //whoAmi fEB.29$ // //样例输出2: //empty //来源 //医学部计算概论2011年期末考试(谢佳亮) #include<fstream> #include<iostream> #include<string> using namespace std; int main() { #ifndef ONLINE_JUDGE ifstream fin("tm201601B.txt"); string myemail, name, pw, email, pw1; bool hasaccount = false; fin >> myemail; int n = 0, i = 0, j = 0; char tmp; fin >> n; for (i=0; i<n; i++) { fin >> name >> pw >> email; if (myemail.compare(email)==0) // string比较用.compare { pw1.clear(); for (j=0; j<pw.size(); j++) { tmp = pw.at(j); if (tmp>='a' && tmp<='z') { tmp += 'A' - 'a'; } else if (tmp>='A' && tmp<='Z') { tmp += 'a' - 'A'; } pw1.push_back(tmp); } cout << name << " " << pw1 << endl; hasaccount = true; } } if (!hasaccount) { cout << "empty"; } fin.close(); #endif #ifdef ONLINE_JUDGE string myemail, name, pw, email, pw1; bool hasaccount = false; cin >> myemail; int n = 0, i = 0, j = 0; char tmp; cin >> n; for (i=0; i<n; i++) { cin >> name >> pw >> email; if (myemail.compare(email)==0) // string比较用.compare { pw1.clear(); for (j=0; j<pw.size(); j++) { tmp = pw.at(j); if (tmp>='a' && tmp<='z') { tmp += 'A' - 'a'; } else if (tmp>='A' && tmp<='Z') { tmp += 'a' - 'A'; } pw1.push_back(tmp); } cout << name << " " << pw1 << endl; hasaccount = true; } } if (!hasaccount) { cout << "empty"; } #endif }