Jawaban #4 Geser-Geser

#include <iostream>
#include <string>
using namespace std;

int main() {
   int jmlcase,jmlgeser;

   int jmlhuruf;

   string a[1000];
   string b[1000];
   string hasil;

	cout << "--------------- Input ----------------\n";

   cout << "Masukkan Jumlah Testcase : "; cin >> jmlcase;

   cout << "Jumlah Pergeseran : "; cin >> jmlgeser;

   for(int i=1;i<=jmlcase;i++){

   	cout << "Kalimat ke - " << i << " : "; cin >> a[i];

   }

	cout << "-------------- Output ----------------\n";

   for(int i=1;i<=jmlcase;i++){
   		hasil = "";

   		jmlhuruf = a[i].size();
   		for(int s=1;s<=jmlhuruf;s++){
   			b[s] = a[i].substr(s-1,1);
   		}

     	for(int j=1;j<=jmlgeser;j++){
     		string temp = b[1];
     		for(int s=1;s<=jmlhuruf;s++){
     			b[s] = b[s+1];
     			if (s==jmlhuruf){
     				b[s] = temp;
     			}
     		}
     		for(int k=1;k<=jmlhuruf;k++){
     			hasil = hasil + b[k];
     		}

     	}
     	cout << hasil << endl;

   }

	return 0;

}

One thought on “Jawaban #4 Geser-Geser

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s