ACM (TJU) : 3070


// http://acm.tju.edu.cn/toj/showp3070.html

#include <stdio.h>

int main ()
{
    int testcase;
    scanf ("%d", &testcase);

    while ( testcase-- ) {

        char str [105];
        scanf ("%s", str);

        int d;
        scanf ("%d", &d);

        for ( int i = 0; str [i] != 0; i++ ) {
            if ( str [i] + d > 'z' ) {
                printf ("%c", 'a' + d - ('z' - str [i]) - 1);
            }
            else
                printf ("%c", str [i] + d);
        }

        printf ("\n");
    }

    return 0;
}

2 thoughts on “ACM (TJU) : 3070

  1. #include <stdio.h>
    
    char arr[26] = {'a','b','c','d','e','f','g','h','i',
    'j','k','l','m','n','o','p','q','r','s','t','u','v',
    'w','x','y','z'};
    
    int index(char ch)
    {
    	int j;
    	for ( int j = 0; j < 26; j++ )
    		if ( ch == arr[j] )
    			break;
    			
    	return j;
    }
    
    int main()
    {
    	char input[101],output[101];
    	int i,a,n,D;
    	
    	scanf("%d",&n);
    	
    	while(n)
    	{
    		scanf("%s %d",input,&D);
    		
    		for(i=0;input[i]!='';i++)
    		{
    			a = index(input[i]);
    			if( a+D >= 26 )
    				output[i] = arr[(a+D)-26];
    
    			else
    				output[i] = arr[a+D];
    		}
    		output[i++] = '';
    		puts(output);
    		fflush(stdout);
    		n--;
    	}
    	return 0;
    }
    
  2. #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
    	int D,testCase;
    	char input[102];
    	scanf("%d",&testCase);
    	while(testCase--){
    		scanf("%s %d",input,&D);
    		for(int i=0;input[i]!='';i++)
    		{
    			char ch = input[i]-'a';
    			ch = ((ch+D)%26)+'a';
    			printf("%c",ch);
    		}
    		printf("\n");
    	}
    	return 0;
    }
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s