Reverse Rot: Difference between revisions

From programming_contest
Jump to navigation Jump to search
imported>Ww109
Created page with "[http://speedyguy17.info/data/mcpc/mcpc2014/rot/rot.html Original Description] == Idea == Manipulate ASCII Numbers Handle special cases by moving them to end of normal cases..."
 
imported>Ww109
No edit summary
Line 1: Line 1:
[http://speedyguy17.info/data/mcpc/mcpc2014/rot/rot.html Original Description]
[http://speedyguy17.info/data/mcpc/mcpc2013/mcpc2013/pdfs/C%20Missing%20Pages.pdf Original Description]
== Idea ==  
== Idea ==  
Manipulate ASCII Numbers
Use the symmetry of the structure: the first two pages are bundled with the last two and so on.


Handle special cases by moving them to end of normal cases
Given an odd P, the other three pages are P + 1, N - P and N - P + 1. For an even P, the other three pages are P - 1, N - P + 1 and N - P + 2.


Then do module to get the results
== Code ==
<syntaxhighlight line lang="cpp">
/*
* =====================================================================================
* Filename: MCPC2013-C.cpp
* Description: Missing Pages
* Compiler: g++
* =====================================================================================
*/


== Code == import java.util.*;
#include <iostream>
public class Reverse_Rot {
#include <set>


public static void encrypt(String s, int k){
using namespace std;
for(int i = s.length()-1; i>=0; i--){
char c = s.charAt(i);
if(c == 95) c = 91;
if(c == 46) c = 92;
c = (char)(c + k);
c = (char)((c - 'A') % 28 + 'A');
if(c == 91) c = 95;
if(c == 92) c = 46;
System.out.print(c);
}
System.out.println();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
int k = scan.nextInt();
if(k == 0)
break;
String s = scan.next();
encrypt(s,k);
}
 
}


int main () {
    int N;
    cin >> N;
    while (N) {
        int P;
        cin >> P;
        set<int> ps;
        if (!(P % 2)) {
            ps.insert(P - 1);
            ps.insert(N - P + 1);
            ps.insert(N - P + 2);
        } else {
            ps.insert(P + 1);
            ps.insert(N - P);
            ps.insert(N - P + 1);
        }
        for (set<int>::iterator i = ps.begin(); i != ps.end(); i++) {
            if (i != ps.begin()) cout << " ";
            cout << *i;
        }
        cout << endl;
        cin >> N;
    }
    return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>
[[Category:mcpc2013]]
[[Category:ICPC Problems]]
[[Category:ICPC Problems]]
[[Category:Implementation Easy]]
[[Category:Implementation Easy]]
[[Category:Algorithm Easy]]
[[Category:Algorithm Easy]]

Revision as of 17:40, 5 December 2015

Original Description

Idea

Use the symmetry of the structure: the first two pages are bundled with the last two and so on.

Given an odd P, the other three pages are P + 1, N - P and N - P + 1. For an even P, the other three pages are P - 1, N - P + 1 and N - P + 2.

Code

/*
 * =====================================================================================
 * Filename: MCPC2013-C.cpp
 * Description: Missing Pages
 * Compiler: g++
 * =====================================================================================
 */

#include <iostream>
#include <set>

using namespace std;

int main () {
    int N;
    cin >> N;
    while (N) {
        int P;
        cin >> P;
        set<int> ps;
        if (!(P % 2)) {
            ps.insert(P - 1);
            ps.insert(N - P + 1);
            ps.insert(N - P + 2);
        } else {
            ps.insert(P + 1);
            ps.insert(N - P);
            ps.insert(N - P + 1);
        }
        for (set<int>::iterator i = ps.begin(); i != ps.end(); i++) {
            if (i != ps.begin()) cout << " ";
            cout << *i;
        }
        cout << endl;
        cin >> N;
    }
    return 0;
}