Sort by

recency

|

53 Discussions

|

  • + 0 comments

    //Answer in java import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.regex.*;

    public class cipher {

    private static final Scanner scanner = new Scanner(System.in);
    
    public static void main(String[] args) {
        int n = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
    
        String s = scanner.nextLine();
    
        int k = scanner.nextInt();
        scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
    
        scanner.close();
        for(int i=0;i<s.length();i++)
        {
            int ch=s.charAt(i);
            if(ch>=97&&ch<=122)
            {
                ch+=k;
                if(ch<=122)
                {
                    System.out.print((char)ch);
                }
                else{
                    while(ch>122)
                    {
                    ch=ch-122;
                    ch=96+ch;
                    }
                    System.out.print((char)ch);
                }
            }
            else if(ch>=65&&ch<=90)
            {
                ch+=k;
                if(ch<=90)
                {
                    System.out.print((char)ch);
                }
                else{
                    while(ch>90)
                    {
                    ch=ch-90;
                    ch=64+ch;
                    }
                    System.out.print((char)ch);
                }
            }
            else{
                System.out.print((char)ch);
            }
        }
    }
    

    }

  • + 0 comments
    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    
    int main() {
        int n;
        cin >> n;
        string s;
        cin >> s;
        int k;
        cin >> k;
            for(int i=0;i<n;i++)
         {   
               if(s[i]>='A' && s[i]<='Z'){ 
                   s[i] = ((s[i] - 65 + k) % 26) + 65;
                   cout<<char(s[i]);
               }
                else if (s[i]>='a' && s[i]<='z'){
                s[i] = ((s[i] - 97 + k) % 26) + 97;
                cout<<char(s[i]);
                 }
                else
                    cout<<char(s[i]);
            }
        return 0;
    }
    
  • + 0 comments

    include

    include

    include

    include

    int main() { int n,i,k; char a[101]; scanf("%d %s %d",&n,a,&k); k%=26; for(i=0;i='a'){ if(a[i]+k>'z') a[i]-=26; a[i]+=k; } else if(a[i]<='Z'&&a[i]>='A'){ a[i]+=k; if(a[i]>'Z') a[i]-=26; } } printf("%s",a);
    return 0; }

  • + 0 comments
    var n = parseInt(readLine());
        var s = readLine();
        var k = parseInt(readLine());
        let finalString = ''
        for (let letter of s) {
          let letra = ''
          if (letter.match(/[a-z]/i)) {
            let asciiL = letter.charCodeAt(0)
            if (asciiL >= 65 && asciiL <= 90) {
              letra = String.fromCharCode(65 + (asciiL - 65 + k) % 26)
    
            }
            if (asciiL >= 97 && asciiL <= 122) {
              letra = String.fromCharCode(97 + (asciiL - 97 + k) % 26)
            }
          } else {
            letra = letter
          }
          finalString += letra
        }
        console.log(finalString)
    
  • + 0 comments

    the code i wrote is :-

    include

    include

    include

    include

    include

    include

    include

    int main(){ int n; scanf("%d",&n); char s[100]; int a[100]; int i; for(i=0;i=65)&&(a[i]<=90)) {s[i]=((s[i]-64+k)%26)+64; printf("%c",s[i]); } else if((a[i]>=97)&&(a[i]<=122)) { s[i]=((s[i]-97+k)%26)+97; printf("%c",s[i]); } else printf("%c",s[i]);

    }
    return 0;
    

    }

    {BUT WHY IS THIS CODE NOT WORKING IF I ENTER A SPECIAL CHARACTER IN BETWEEN?}