随便写了下
/**********************************************************************************/
/* Problem: b030 "E. 達文西密碼" from 2006 NPSC 國中組初賽 */
/* Language: CPP (814 Bytes) */
/* Result: AC(8ms, 424KB) judge by this@ZeroJudge */
/* Author: rosynirvana at 2013-10-07 21:07:06 */
/**********************************************************************************/
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
using std::string;
using std::vector;
int main()
{
string s1, s2;
while(std::getline(std::cin, s1)){
vector<int> count1(52, 0), count2(52, 0);
std::getline(std::cin, s2);
for(size_t i=0; i!=s1.size(); ++i)
if(islower(s1[i]))
count1[s1[i] - 'a'] += 1;
else if(isupper(s1[i]))
count1[s1[i] - 'A' + 26] += 1;
for(size_t i=0; i!=s2.size(); ++i)
if(islower(s2[i]))
count2[s2[i] - 'a'] += 1;
else if(isupper(s2[i]))
count2[s2[i] - 'A' + 26] += 1;
bool same = true;
for(int i=0; i!=52; ++i)
if(count1[i] != count2[i]){
same = false;
break;
}
if(same)
std::cout << "Yes\n";
else
std::cout << "No\n";
}
return 0;
}
凭感觉,只要用整行读取都不会有问题的
随便写了下
/**********************************************************************************/
/* Problem: b030 "E. 達文西密碼" from 2006 NPSC 國中組初賽 */
/* Language: CPP (814 Bytes) */
/* Result: AC(8ms, 424KB) judge by this@ZeroJudge */
/* Author: rosynirvana at 2013-10-07 21:07:06 */
/**********************************************************************************/
#include
#include
#include
#include
using std::string;
using std::vector;
int main()
{
string s1, s2;
while(std::getline(std::cin, s1)){
vector count1(52, 0), count2(52, 0);
std::getline(std::cin, s2);
for(size_t i=0; i!=s1.size(); ++i)
if(islower(s1[i]))
count1[s1[i] - 'a'] += 1;
else if(isupper(s1[i]))
count1[s1[i] - 'A' + 26] += 1;
for(size_t i=0; i!=s2.size(); ++i)
if(islower(s2[i]))
count2[s2[i] - 'a'] += 1;
else if(isupper(s2[i]))
count2[s2[i] - 'A' + 26] += 1;
bool same = true;
for(int i=0; i!=52; ++i)
if(count1[i] != count2[i]){
same = false;
break;
}
if(same)
std::cout << "Yes\n";
else
std::cout << "No\n";
}
return 0;
}
凭感觉,只要用整行读取都不会有问题的
为什么我会TLE了。。。
#include <cstdio>
char s1[1000], s2[1000];
int main(){
while(gets(s1)!=0){
gets(s2);
int ca[150]={}, cb[150]={}, right=1, i;
for(i=0; s1[i]!=0, s2[i]!=0; i++){
ca[int(s1[i])]++;
cb[int(s2[i])]++;
}
while(s1[i]!=0) ca[int(s1[i])]++;
while(s2[i]!=0) cb[int(s2[i])]++;
for(int i='A'; i<='z'; i++) if(ca[i]!=cb[i]){right=0; break;}
if(right) printf("Yes\n");
else printf("No\n");
}
return 0;
}
随便写了下
/**********************************************************************************/
/* Problem: b030 "E. 達文西密碼" from 2006 NPSC 國中組初賽 */
/* Language: CPP (814 Bytes) */
/* Result: AC(8ms, 424KB) judge by this@ZeroJudge */
/* Author: rosynirvana at 2013-10-07 21:07:06 */
/**********************************************************************************/
#include
#include
#include
#include
using std::string;
using std::vector;
int main()
{
string s1, s2;
while(std::getline(std::cin, s1)){
vector count1(52, 0), count2(52, 0);
std::getline(std::cin, s2);
for(size_t i=0; i!=s1.size(); ++i)
if(islower(s1[i]))
count1[s1[i] - 'a'] += 1;
else if(isupper(s1[i]))
count1[s1[i] - 'A' + 26] += 1;
for(size_t i=0; i!=s2.size(); ++i)
if(islower(s2[i]))
count2[s2[i] - 'a'] += 1;
else if(isupper(s2[i]))
count2[s2[i] - 'A' + 26] += 1;
bool same = true;
for(int i=0; i!=52; ++i)
if(count1[i] != count2[i]){
same = false;
break;
}
if(same)
std::cout << "Yes\n";
else
std::cout << "No\n";
}
return 0;
}
凭感觉,只要用整行读取都不会有问题的
为什么我会TLE了。。。
#include
char s1[1000], s2[1000];
int main(){
while(gets(s1)!=0){
gets(s2);
int ca[150]={}, cb[150]={}, right=1, i;
for(i=0; s1[i]!=0, s2[i]!=0; i++){
ca[int(s1[i])]++;
cb[int(s2[i])]++;
}
while(s1[i]!=0) ca[int(s1[i])]++;
while(s2[i]!=0) cb[int(s2[i])]++;
for(int i='A'; i<='z'; i++) if(ca[i]!=cb[i]){right=0; break;}
if(right) printf("Yes\n");
else printf("No\n");
}
return 0;
}
tle的好像是这里
while(s1[i]!=0) ca[int(s1[i])]++;
while(s2[i]!=0) cb[int(s2[i])]++;
另外如果两个字符串不一样长,所以写for(i=0; s1[i] != 0 , s2[i] != 0; ....)是有可能RE的