csuoj 1396: Erase Securely

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1396

1396: Erase Securely

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 102  Solved: 60
[Submit][Status][Web Board]

Description

Input

Output

Sample Input

1
10001110101000001111010100001110
01110001010111110000101011110001

Sample Output

Deletion succeeded

HINT

Source

分析;
就是01互换,然后对比两个串的异同。

AC代码:

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<queue>
 5 #include<iostream>
 6 #include<stack>
 7 #include<map>
 8 #include<string>
 9 using namespace std;
10 char ch1[1050], ch2[1050];
11 int main(){
12     int n;
13     while(~scanf("%d", &n)){
14         scanf("%s%s", ch1, ch2);
15         int l = strlen(ch1);
16         if(n%2 == 1)
17             for(int i = 0; i < l; i++)
18                 if(ch1[i] == '1')
19                     ch1[i]--;
20                 else if(ch1[i] == '0')
21                     ch1[i]++;
22         if(strcmp(ch1, ch2) == 0)
23             printf("Deletion succeeded
");
24         else
25             printf("Deletion failed
");
26     }
27     return 0;
28 }
原文地址:https://www.cnblogs.com/jeff-wgc/p/4475392.html